我总是不断收到类型错误,说我缺少1个必需的位置参数,这是“自我”,我该如何解决呢?from tkinter import *import tkinterfrom client import*root = tkinter.Tk()class view(): root.geometry("250x300") F1 =Frame() L = Listbox(F1) L.grid(row=0, column =0) L.pack() F = open("users.txt","r") M = F.read() cont = M.split() for each in cont: ind = each.find("#") + 1 L.insert(ind+1 ,each[ind:]) break F.close() F1.pack() # strng_ind = -1def button_click(self): self.form.destroy() Chatclient().design()button = Button(root, text="Create Group Chat", command= button_click)button.pack()root.mainloop()
3 回答

眼眸繁星
TA贡献1873条经验 获得超9个赞
问题在这里:
button = Button(root, text="Create Group Chat", command= button_click)
注意命令-它说要调用button_click
,并且将不带参数。您将点击功能定义为
def button_click(self):
因此,当您单击按钮button_click
并不带任何参数调用时,由于您的定义需要一个自变量-无论是因为它在类中还是出于某种原因-您都会收到错误。摆脱self
参数
def button_click():
或者如果应该将其作为类定义的一部分,则仅使用有效的对象定义Button。例如,您可以放入def __init__(self)
:
self.button = Button(root, text="Create Group Chat", command= self.button_click)
加上在构造函数中构造GUI的额外好处,这是很好的设计。
添加回答
举报
0/150
提交
取消