我總是不斷收到類型錯誤,說我缺少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
提交
取消