我是使用 Python 的图形用户界面的新手。在登录页面单击“注册”按钮后,我试图打开“注册”页面。然后,点击“返回登录”返回登录页面。但它没有用。
login.py
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
from register import Register
class Login:
def __init__(self):
self.loginw = Tk()
self.loginw.title("Login")
self.loginw.geometry("500x500")
self.signin = Button(self.loginw,width=20, text="Register", command=self.register)
self.signin.place(relx=0.5, rely=0.5, anchor=CENTER)
def register(self):
self.loginw.quit()
win = Toplevel()
Register(win)
w=Login()
w.loginw.mainloop()
register.py
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
class Register:
def __init__(self):
self.reg = Tk()
self.reg.title("Register")
self.reg.geometry("500x500")
self.revert = Button(self.reg,width=20, text="Return to Login")
self.revert.place(relx=0.5, rely=0.5, anchor=CENTER)
单击注册按钮后出现的错误
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\me\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "c:\Users\me\Documents\Education\Testing code\login.py", line 18, in register
Register(win)
TypeError: Register.__init__() takes 1 positional argument but 2 were given
太感谢了。