使用 if 标签在 tlinker 中不起作用
我正在尝试使用 tkinter 进行实验,但我的代码无法正常工作。谁能告诉我我做错了什么?
import tkinter as tk
window = tk.Tk()
frame = tk.Frame(master=window, width=150, height=150)
frame.pack()
label1 = tk.Label(master=frame, text="I'm at (0, 0)", bg="red")
label1.place(x=0, y=0)
label2 = tk.Label(master=frame, text="I'm at (75, 75)", bg="yellow")
Question = input("your question")
if Question == ("yes"):
print ("well done")
elif Question == ("no"):
print ("try again")
label3 = tk.Label(master=frame, text="I'm at (75, 75)", bg="yellow")
label3.place(x=75, y=75)
window.mainloop()
I am trying to do experiments with tkinter, but my code isn't working. Can anyone tell me what am I doing wrong?
import tkinter as tk
window = tk.Tk()
frame = tk.Frame(master=window, width=150, height=150)
frame.pack()
label1 = tk.Label(master=frame, text="I'm at (0, 0)", bg="red")
label1.place(x=0, y=0)
label2 = tk.Label(master=frame, text="I'm at (75, 75)", bg="yellow")
Question = input("your question")
if Question == ("yes"):
print ("well done")
elif Question == ("no"):
print ("try again")
label3 = tk.Label(master=frame, text="I'm at (75, 75)", bg="yellow")
label3.place(x=75, y=75)
window.mainloop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在制作 GUI 时,
input
可以替换为tk.Entry
输入仅用于控制台。我向tk.Label
、tkEntry
和en.bind
添加了一项功能和其他小部件。我替换了你的代码并将重新写入我的代码中。这是代码:
只需按 Enter 键即可。
是的结果:
否的结果:
The
input
can be substituted totk.Entry
while making GUI The input is merely used for console. I added one more feature and additional widgets totk.Label
,tkEntry
anden.bind
. I substituted in your code and will re-wrote into my code.Here is code:
Just press enter.
Result for yes:
Result for no: