我在这里做错了什么?
我正试图从__init__
var - self.username_entry
但是python总是说:user_reg() missing 1 required positional argument: 'self'
class Register_user:
def __init__(self):
root = Tk()
root.geometry("300x250")
root.title("Games V1.0")
self.username = StringVar()
self.password = StringVar()
root.label1 = Label(root, text="Nickname ").pack()
root.emlabel = Label(root, text="").pack()
self.username_entry= Entry(root, textvariable=username)
self.username_entry.pack()
root.emlabel = Label(root, text="").pack()
root.label2 = Label(root, text="Password*").pack()
self.password_entry = Entry(root, show='*', textvariable=password)
self.password_entry.pack()
self.bt1 = Button(root, text="Register", width=10, height=1, command=self.user_reg).pack()
root.mainloop()
def user_reg(self): # Register the user only if the nickname avilible
username = self.username_entry
password = self.password_entry
list_of_files = os.listdir() # list of files on the directory
if username in list_of_files:
reg_failed_user(self)
username.delete(0, END)
password.delete(0, END)
else:
file = open(username, "w")
file.write(password)
self.username_entry.delete(0, END)
self.password_entry.delete(0, END)
reg_success(self)
def reg_failed_user(self):
pass
def reg_success(self):
pass