tkinter button command报错missing 1 required positional argument: 'self'已解决

代码

class Note:
    def initView(self):
        self.signInViewButton.place(x=0,y=200)
        pass
    def signInView(self):
        self.titleLabel.pack(side='top')
        pass
    window=tk.Tk()
    titleLabel=tk.Label(window, text='笔记', bg='gray',fg='white', font=('Arial', 16), width=32, height=4)
    signInViewButton=tk.Button(window,text='登录',bg='green',fg='white',font=('Arial','12'),width='10',height='1',command=signInView)
    def  __init__(self):
        self.window.title('biji')
        self.window.geometry('800x500+100+100')
        self.initView()
        self.window.mainloop()
        pass
notes = Note()

按钮连接了signInView函数

点击按钮报错如下

Exception in Tkinter callback
Traceback (most recent call last):
  File "D:\python\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
TypeError: signInView() missing 1 required positional argument: 'self'

查了之后只有https://stackoverflow.com/questions/20815887/missing-1-required-positional-argumentself可以参考

posted @ 2021-03-16 10:42  Jelle  阅读(444)  评论(0编辑  收藏  举报