所以我有問題。我正在嘗試使用按鈕制作一個程式,因此您可以選擇帶有按鈕的東西。我正在運行 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")
我嘗試添加它,它只是不起作用:(
感謝所有幫助!
uj5u.com熱心網友回復:
(對不起,英語不好)你必須把按鈕的動作放在它們的功能中。
試試這個:
def choiceFirst():
print("choice 1 code here")
def choiceSeco():
print("Choice 2 code here")
并洗掉 if 陳述句。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/398960.html
