python - 我怎样才能使这个文本条目/框架整体消失?
问题描述
所以我想让我制作的这个框架在按下按钮后消失。继承人的代码:
import tkinter as tk
root = tk.Tk()
root.geometry("150x50+680+350")
def FormSubmission():
global button_start
root.attributes("-fullscreen", True)
frame = tk.Frame(root)
tk.Label(frame, text="First Name:").grid(row=0)
entry1 = tk.Entry(frame)
entry1.grid(row=0, column=1)
tk.Label(frame, text="Last Name:").grid(row=1)
e2 = tk.Entry(frame)
e2.grid(row=1, column=1)
tk.Label(frame, text="Email:").grid(row=2)
e3 = tk.Entry(frame)
e3.grid(row=2, column=1)
tk.Label(frame, text="Date of Birth:").grid(row=3)
e4 = tk.Entry(frame)
e4.grid(row=3, column=1)
frame.pack(anchor='center', expand=True)
button_next = tk.Button(root, text = "Next", height = 2, width = 7, command = MainPage).pack()
button_start.place_forget()
def MainPage():
global FormSubmission
root.attributes("-fullscreen", True)
l1 = tk.Label(root, text = "Welcome Back," , font = ("Arial", 44)).pack()
button_start.place_forget() # You can also use `button_start.destroy()`
button_start = tk.Button(root, text="Start", height=3, width=20, command = FormSubmission)
button_start.place(x = 0, y = 10)
button_exit = tk.Button(root, text="Exit", command=root.destroy)
button_exit.place(x=1506, y=0)
root.mainloop()
如您所见,我想让输入字段的框架/功能(FormSubmission)在功能(MainPage)中按下下一个按钮后消失。
解决方案
您可以使用pack_forget
每个几何管理器(包、网格、位置)都有自己的..._forget
我已经为您希望的用例重新编辑了您的代码段。
无论如何,我认为您应该重新设计您的应用程序。
import tkinter as tk
root = tk.Tk()
root.geometry("150x50+680+350")
def FormSubmission():
global button_start
root.attributes("-fullscreen", True)
frame = tk.Frame(root)
tk.Label(frame, text="First Name:").grid(row=0)
entry1 = tk.Entry(frame)
entry1.grid(row=0, column=1)
tk.Label(frame, text="Last Name:").grid(row=1)
e2 = tk.Entry(frame)
e2.grid(row=1, column=1)
tk.Label(frame, text="Email:").grid(row=2)
e3 = tk.Entry(frame)
e3.grid(row=2, column=1)
tk.Label(frame, text="Date of Birth:").grid(row=3)
e4 = tk.Entry(frame)
e4.grid(row=3, column=1)
frame.pack(anchor='center', expand=True)
button_next = tk.Button(root, text = "Next", height = 2, width = 7, command = lambda: MainPage(frame)).pack()
button_start.place_forget()
def MainPage(frame):
global FormSubmission
frame.pack_forget()
root.attributes("-fullscreen", True)
l1 = tk.Label(root, text = "Welcome Back," , font = ("Arial", 44)).pack()
button_start.place_forget() # You can also use `button_start.destroy()`
button_start = tk.Button(root, text="Start", height=3, width=20, command = FormSubmission)
button_start.place(x = 0, y = 10)
button_exit = tk.Button(root, text="Exit", command=root.destroy)
button_exit.place(x=1506, y=0)
root.mainloop()
推荐阅读
- python - 如果网络接口暂时关闭,是否需要超时以防止 `requests.get()` 阻塞?
- java - 如何修复 Spring Boot 应用程序的 UTF-8 编码?
- c++ - 在 C++ 中插入地图
- excel - 使用 Cells.Find 时出现运行时错误 91
- json - 使用 resttemplate Exchange 在 POST 请求正文中发送参数和列表
- java - 如何使用 JtextArea 添加滚动条并在 GUI 中实现 JScrollPane?
- php - 如何在 laravel 和 mysql 中选择和更新 10 个随机行
- c# - 从另一个线程更新 Datagrid 的 ItemSource
- curl - 使用 Curl 下载 HTML 进行解析的问题
- javascript - Google reCAPTCHA 在 .NET WebForms 中不起作用