[英]Tkinter: How do I clear the window?
So this program asks for a name and last name. 因此,该程序要求输入名称和姓氏。 I'm looking for the program to clear and show "Welcome " + name + " " + lastname.
我正在寻找要清除并显示“ Welcome” +名称+“” +姓氏的程序。
import sys
from tkinter import *
def salir():
sys.exit()
root = Tk()
root.wm_title('Matricula UTEC')
Label(root, text = "Bienvenido a Matricula UTEC").grid(row = 0)
Label(root, text = "Ingrese sus nombres: ").grid(row = 1)
Label(root, text = "Ingrese sus apellidos: ").grid(row = 2)
e1 = Entry(root)
e2 = Entry(root)
e1.grid(row=1, column = 1)
e2.grid(row=2, column = 1)
Button(root, text = 'Salir', command = salir).grid(row = 4, column = 0, sticky = W, pady = 4)
Button(root, text = 'Comenzar', command = salir).grid(row = 4, column = 1, sticky = W, pady = 4)
root.mainloop()
The simplest solution is to put everything you want to "clear" in a frame. 最简单的解决方案是将您要“清除”的所有内容放入框架中。 Then, you can simply delete the frame and replace it with a different frame.
然后,您可以简单地删除框架并将其替换为其他框架。
Here's a really simple example: 这是一个非常简单的示例:
import sys
from tkinter import *
def salir():
login_frame.destroy()
home_frame = home()
home_frame.pack(fill="both", expand=True)
def login():
frame = Frame(root)
Label(frame, text = "Bienvenido a Matricula UTEC").grid(row = 0)
Label(frame, text = "Ingrese sus nombres: ").grid(row = 1)
Label(frame, text = "Ingrese sus apellidos: ").grid(row = 2)
e1 = Entry(frame)
e2 = Entry(frame)
e1.grid(row=1, column = 1)
e2.grid(row=2, column = 1)
Button(frame, text = 'Salir', command = salir).grid(row = 4, column = 0, sticky = W, pady = 4)
Button(frame, text = 'Comenzar', command = salir).grid(row = 4, column = 1, sticky = W, pady = 4)
return frame
def home():
frame = Frame(root)
Label(frame, text="Welcome").pack()
return frame
root = Tk()
root.wm_title('Matricula UTEC')
login_frame = login()
login_frame.pack(fill="both", expand=True)
root.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.