Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使此文本条目/框架作为一个整体消失?_Python_User Interface_Tkinter_Frame - Fatal编程技术网

Python 如何使此文本条目/框架作为一个整体消失?

Python 如何使此文本条目/框架作为一个整体消失?,python,user-interface,tkinter,frame,Python,User Interface,Tkinter,Frame,所以我想让我制作的这个框架在按下按钮后消失。代码如下: 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

所以我想让我制作的这个框架在按下按钮后消失。代码如下:

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)消失。

您可以使用
pack\u forget

每个几何图形管理器(包、网格、位置)都有自己的
。\u忘记

我已经根据您希望的用例重新编辑了您的代码片段

无论如何,我认为你应该重新设计你的应用程序

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()

感谢您提供这段代码片段,它可能会提供一些有限的、即时的帮助。通过展示为什么这是一个很好的问题解决方案,A将极大地提高它的长期价值,并将使它对未来有其他类似问题的读者更有用。请在你的答案中添加一些解释,包括你所做的假设。我详细阐述了我的答案。