[英]How to add an if statement to a Tkinter program
from tkinter import *
window=Tk()
btn=Button(window, text="Yes", fg='blue')
btn.place(x=100, y=100)
btn=Button(window, text="No", fg='blue')
btn.place(x=250, y=100)
window.title('Test')
window.geometry("400x600+10+10")
window.mainloop()
I am trying to create it so that when I press the 'Yes' button it will do something (which I have not yet coded) but I don't know how to save the button press input as a variable or have I got it all wrong?我正在尝试创建它,以便当我按下“是”按钮时它会做一些事情(我还没有编码)但我不知道如何将按钮按下输入保存为变量或者我得到了这一切错误的?
:) :)
from tkinter import *
window=Tk()
def something():
print('hello')
btn=Button(window, text="Yes", fg='blue', command = something)
btn.place(x=100, y=100)
btn=Button(window, text="No", fg='blue')
btn.place(x=250, y=100)
window.title('Test')
window.geometry("400x600+10+10")
window.mainloop()
clicking on your button will call the function that you put in command
, which is called something
, you can put your code in there.单击您的按钮将调用您输入的command
function,这称为something
,您可以将代码放在那里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.