我正在使用 tkinter 创建登录/注册系统。当用户单击登录或注册时,我希望所有小部件都消失,以便新的小部件出现在屏幕上,具体取决于他们是否单击了登录或注册。因此,如果他们点击登录,新的标签和文本框将显示他们的用户名和密码。问题是我正在使用 .place() 并且我看到的教程主要是使用pack_forget
orgrid_forget
我的代码:
from tkinter import *
class Window:
def __init__(self, master):
root.title("Sign Up or Login")
root.minsize(width=300, height=300)
root.maxsize(width=300,height=300)
self.login_button = Button(master, text = "Login", width=18,height=4, command=self.LoginPage)
self.signup_button = Button(master, text = "Sign Up", width=18,height=4, command=self.SignupPage)
self.login_button.place(relx=0.5, rely=0.3, anchor=CENTER)
self.signup_button.place(relx=0.5, rely=0.7, anchor=CENTER)
def LoginPage(self):
root.title("Login")
def SignupPage(self):
root.title("Sign Up")
root = Tk()
run = Window(root)
root.mainloop()
我的界面: