我有點麻煩了。我正在嘗試將函數綁定到 Python 的 tkinter 模塊中的鼠標單擊。每次單擊時,該函數都會為變量加 1。該函數不帶參數。但是,當我將該功能綁定到鼠標單擊時,它說:TypeError: func() takes 0 positional arguments but 1 was given.我從未給函數提供任何參數,只是將其綁定到鼠標單擊,Python 仍然認為我做錯了什么。幫助?代碼附后。from tkinter import *root = Tk()root.geometry('800x600')root.title("Sim Game")c = Canvas(root, height=400, width=600, bg='red')x = 0def func(): global x x += 1c.bind("<Button-1>", func)c.pack()root.mainloop()
添加回答
舉報
0/150
提交
取消