Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.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
在按钮上隐藏帧按tkinter python_Python_Tkinter - Fatal编程技术网

在按钮上隐藏帧按tkinter python

在按钮上隐藏帧按tkinter python,python,tkinter,Python,Tkinter,我的箭就像一个指针。如果将其添加到代码中,则可以将其删除。它是不需要的,如果你不删除它,它会弄乱你的代码 我正在使用python 2.7.1和Tkinter 我这里有代码: # | this is where the show frame part is. | # |---------------------------------------| | |__ | def clic

我的箭就像一个指针。如果将其添加到代码中,则可以将其删除。它是不需要的,如果你不删除它,它会弄乱你的代码

我正在使用python 2.7.1和Tkinter

我这里有代码:

# | this is where the show frame part is. |
# |---------------------------------------|
                   |
                   |__
                     |
def click_start():   |
        |____________|
        V
   f2.pack(after=f1, anchor=W, padx=5, pady=10)

f1 = Frame(root, width=10, height=20, bd=0, bg="#dcd9d3", pady=4, 
relief=FLAT).pack(side=TOP, anchor=W)

f2 = Frame(root, width=10, height=20, bd=0, bg="black", pady=4)

file_button = ttk.Button(f1, text="File", padding=3.5, width=3.5, 
command=click_start).pack(side=LEFT)
我现在不知道如何隐藏名为f2的帧。我想要这样,当我按下文件按钮时,它将显示名为f2的帧(我已经完成了这部分)

现在,如果我再次按下文件按钮,我需要隐藏它


然后我需要循环此函数,这样我就可以无限地执行此操作。

由于您在帧上使用了
pack()
,那么您可以使用
pack\u forget()
从当前的包管理器中删除帧。如果要切换框架的可见性,可以使用
winfo_manager()
检查框架是否由任何布局管理器管理

只需修改
单击\u start()
,如下所示:

def click_start():
    f2.pack_forget() if f2.winfo_manager() else f2.pack(after=f1, anchor=W, padx=5, pady=10)
用于python 3

f2.将忘记()打包以隐藏 如果使用f2.pack()来显示

而且

f2.要隐藏的网格 如果使用f2.grid()来显示

f2.将_忘记()放置在隐藏位置
如果您使用f2.place()来显示

请阅读为什么您要说“for Python3”?这对Python2也是有效的,因为我在Python3中使用了它。不知道在Python2中运行的是什么。