所以我有一个问题。我试图用按钮制作一个程序,所以你可以选择带有按钮的东西。我正在运行 python 3。
我制作了按钮,定制了它们,按钮一切都很好。
def choiceFirst():
choice = 1
buttonPressed = True
def choiceSeco():
choice = 2
buttonPressed = True
window = Tk()
window.title("Title lol")
icon = PhotoImage(file='download.png')
window.geometry("300x215")
window.iconphoto(True,icon)
button1 = Button(window,
text="Choice 1",
command=choiceFirst,
font=("Arial", 20),
fg='#00f000',
bg='white',
relief=RAISED,
bd=10,
padx=20,
pady=20,
activeforeground='#00f000',
activebackground="white",)
button2 = Button(window,
text="Choice 2",
command=choiceSeco,
font=("Arial", 20),
fg='#00f000',
bg='white',
relief=RAISED,
bd=10,
padx=15,
pady=15,
activeforeground='#00f000',
activebackground="white",)
button1.pack()
button2.pack()
window.mainloop()
现在我想添加一个 if 语句。就像是
if buttonPressed:
if choice == 1:
print("choice 1 code here")
elif choice ==2:
print("Choice 2 code here")
我尝试添加它,它只是不起作用:(
感谢所有帮助!