我如何编辑我到目前为止所做的代码,以便当我单击按钮 'signup' 时,它会关闭该 gui 并打开下一个
How can i edit this code i've made so far so that when i click the button 'signup' it closes that gui and opens the next one
我正在使用 tkinter 制作一个图形用户界面并制作了各种不同的按钮,现在我已经制作了所有这些我不确定如何在第二个打开时正确关闭第一个图形用户界面框(sign_in 功能)
from tkinter import *
class login:
def __init__(self, master):
frame = Frame(master)
frame.grid()
self.button1 = Button(frame, text="signup", fg="green",command=self.sign_in)
self.button2 = Button(frame, text="sign in", fg="black",)
self.button3 = Button(frame, text="quit", fg="red", command=frame.master.destroy)
self.button1.grid(stick=W)
self.button2.grid(stick=W)
self.button3.grid(stick=W)
def sign_in(self):
frame = Frame()
frame.grid()
name = Label(root, text="Name: ")
password = Label(root, text="password: ")
entry1 = Entry(root)
entry2 = Entry(root)
name.grid(row=0, sticky=E)
password.grid(row=1, sticky=E)
entry1.grid(row=0, column=1)
entry2.grid(row=1, column=1)
c = Checkbutton(root, text="keep me logged in")
c.grid(columnspan=2, sticky="w")
root = Tk()
account=login(root)
root.mainloop()
您的代码包含一些缩进错误,所以我将按照您的问题进行处理。
when i click the button 'signup' it closes that gui and opens the next one
您可以先撤回您的根 window,如下所示:root.withdraw()
这将隐藏您原来的 window。然后像这样创建一个 Toplevel window:newWindow = tk.Toplevel(root)
创建一个新的 window。您只需将这些行放在按钮命令调用中。
这是您可以在 sign_in
中更改的内容,注意我将所有母版更改为 frame
而不是 root
:
def sign_in(self):
root.withdraw()
frame = Toplevel(root)
name = Label(frame, text="Name: ")
password = Label(frame, text="password: ")
entry1 = Entry(frame)
entry2 = Entry(frame)
name.grid(row=0, sticky=E)
password.grid(row=1, sticky=E)
entry1.grid(row=0, column=1)
entry2.grid(row=1, column=1)
c = Checkbutton(frame, text="keep me logged in")
c.grid(columnspan=2, sticky="w")
我正在使用 tkinter 制作一个图形用户界面并制作了各种不同的按钮,现在我已经制作了所有这些我不确定如何在第二个打开时正确关闭第一个图形用户界面框(sign_in 功能)
from tkinter import *
class login:
def __init__(self, master):
frame = Frame(master)
frame.grid()
self.button1 = Button(frame, text="signup", fg="green",command=self.sign_in)
self.button2 = Button(frame, text="sign in", fg="black",)
self.button3 = Button(frame, text="quit", fg="red", command=frame.master.destroy)
self.button1.grid(stick=W)
self.button2.grid(stick=W)
self.button3.grid(stick=W)
def sign_in(self):
frame = Frame()
frame.grid()
name = Label(root, text="Name: ")
password = Label(root, text="password: ")
entry1 = Entry(root)
entry2 = Entry(root)
name.grid(row=0, sticky=E)
password.grid(row=1, sticky=E)
entry1.grid(row=0, column=1)
entry2.grid(row=1, column=1)
c = Checkbutton(root, text="keep me logged in")
c.grid(columnspan=2, sticky="w")
root = Tk()
account=login(root)
root.mainloop()
您的代码包含一些缩进错误,所以我将按照您的问题进行处理。
when i click the button 'signup' it closes that gui and opens the next one
您可以先撤回您的根 window,如下所示:root.withdraw()
这将隐藏您原来的 window。然后像这样创建一个 Toplevel window:newWindow = tk.Toplevel(root)
创建一个新的 window。您只需将这些行放在按钮命令调用中。
这是您可以在 sign_in
中更改的内容,注意我将所有母版更改为 frame
而不是 root
:
def sign_in(self):
root.withdraw()
frame = Toplevel(root)
name = Label(frame, text="Name: ")
password = Label(frame, text="password: ")
entry1 = Entry(frame)
entry2 = Entry(frame)
name.grid(row=0, sticky=E)
password.grid(row=1, sticky=E)
entry1.grid(row=0, column=1)
entry2.grid(row=1, column=1)
c = Checkbutton(frame, text="keep me logged in")
c.grid(columnspan=2, sticky="w")