【发布时间】:2021-06-29 11:43:31
【问题描述】:
所以,当您使用 config 和 if 语句将内容放入此条目时,我有点希望这个小型机器人能够与您交谈并做出响应,但它似乎并没有真正起作用。我现在的问题是,当我进行配置时,这里的标签正在改变。这是我的代码:
import tkinter as tk
root = tk.Tk()
root.attributes('-fullscreen', True)
exit_button = tk.Button(root, text="Exit", command = root.destroy)
exit_button.place(x=1506, y=0)
def answer():
global main_entry, answer_label
if main_entry == "Hey":
answer_label.config(Text = "Hi")
frame = tk.Frame(root)
main_entry = tk.Entry(frame, width=100)
main_entry.grid(row=0, column=0)
go_button = tk.Button(frame, text='Go!', width=85, command = answer)
go_button.grid(row=1, column=0)
answer_label = tk.Label(text = "Hello!").pack()
frame.place(relx=.5, rely=.5, anchor='center')
root.mainloop()
问题是 if 语句不起作用,它没有更改 ext,但我也没有收到任何错误消息,所以我有点困惑。
【问题讨论】:
标签: python python-3.x if-statement tkinter pycharm