python - 为什么当我使用配置选项时这个标签没有改变?
问题描述
因此,当您使用 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,但我也没有收到任何错误消息,所以我有点困惑。
解决方案
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():
getanswer=main_entry.get()
if getanswer == "Hey":
answer_label.configure(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!")
answer_label.pack()
frame.place(relx=.5, rely=.5, anchor='center')
root.mainloop()
推荐阅读
- android - 如何使 onLocationResult 函数起作用?我
- amazon-web-services - 我的 lambda 和 EC2 在 VPC 中,我无法从 lambda 将记录放入 kinesis,但我可以从 EC2
- javascript - 重用 MongoDB 连接的正确方法是什么?
- xml - 使用 SQL 查询从 Oracle Report Builder 生成 XML 文件
- ios - 重新加载时带有 UIRefreshControl 的 TableView 似乎有点小故障?
- botframework - 任务模块机器人框架
- javascript - 重新加载页面时 gapi.auth2.getAuthInstance() 为空
- ionic-framework - “src\app\app.module.ts(60,22) 中的错误:在模板编译 'AppModule' 期间出错”,同时使用 cordova 将离子应用程序构建到 ios --prod
- python - TypeError:类型函数的对象不是 JSON 可序列化的
- python - 如何使用所有可能的构造函数参数排列来测试对象/类?