這是有問題的代碼的一部分,它有點混亂,但是當我運行代碼時,只有button1可以使用。其他按鈕出現,可以點擊,但沒有任何反應。任何想法發生了什麼? Im相當肯定它是與綁定的一部分,但我不能修復它,它看起來好像沒什麼問題,但它不提前工作,所以......哈哈感謝在Python中不工作的按鈕Tkinter代碼
##Buttons##
self.button1 = Button(self.canvays)
self.button1.configure(text="Pride", background="red")
self.button1.pack(side=RIGHT)
self.button1.focus_force()
self.button1.place(x=85, y=367)
self.button1.bind("<Button-1>", self.button1Click)
self.button2 = Button(self.canvays)
self.button2.configure(text="Murder", background="blue")
self.button2.pack(side=TOP)
self.button2.focus_force()
self.button2.place(x=225, y=367)
self.button2.bind("<Button-2>", self.button2Click)
self.button3 = Button(self.canvays)
self.button3.configure(text="Lions", background="Yellow")
self.button3.pack(side=TOP)
self.button3.focus_force()
self.button3.place(x=380, y=367)
self.button3.bind("<Button-3>", self.button3Click)
self.root.mainloop()
def incorrect(self):
self.labelincorrect = Label(text = "Sorry that wasnt right, try again")
self.labelincorrect.pack(side=TOP)
self.labelincorrect.place(x=250, y=250)
def correct(self):
self.score = self.score+1
##Button Event##
def button3Click(self, event):
self.incorrect()
def button2Click(self, event):
self.incorrect()
def button1Click(self, event):
self.root.destroy()
self.correct()
Question2()
您是否知道您將鼠標滾輪按鈕綁定到'button2',並右鍵單擊到'button3'?如果你想要正常的行爲,你根本不需要綁定任何按鈕。默認情況下它們的行爲與按鈕相似有關更多信息,請參閱Tkinter上的教程。 – TigerhawkT3