[英]hide frame on button press tkinter python
my arrow thing is just like a pointer.我的箭头就像一个指针。 you can delete it if you add it to your code.
如果将其添加到代码中,则可以将其删除。 It is not needed and will mess up your code if you don't delete it
它不是必需的,如果你不删除它会弄乱你的代码
I am using python 2.7.1 and Tkinter.我正在使用 python 2.7.1 和 Tkinter。
I have the code here:我这里有代码:
# | 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)
I now don't know how to hide the frame named f2.我现在不知道如何隐藏名为 f2 的框架。 I want it so that when I press the file button, it will show the frame called f2 (I have done this part.)
我想要这样,当我按下文件按钮时,它会显示名为 f2 的框架(我已经完成了这部分。)
Now, I need to hide it if I push the file button again.现在,如果我再次按下文件按钮,我需要隐藏它。
Then I need to loop this function so that I can do this infinitely.然后我需要循环这个函数,这样我就可以无限地做到这一点。
As you have used pack()
on the frames, then you can use pack_forget()
to remove the frame from the current pack manager.由于您在框架上使用了
pack()
,因此您可以使用pack_forget()
从当前的包管理器中删除该框架。 If you want to toggle the visibility of the frame, you can use winfo_manager()
to check whether the frame is managed by any layout manager.如果要切换框架的可见性,可以使用
winfo_manager()
来检查框架是否由任何布局管理器管理。
Just modify click_start()
as below:只需修改
click_start()
如下:
def click_start():
f2.pack_forget() if f2.winfo_manager() else f2.pack(after=f1, anchor=W, padx=5, pady=10)
use for python 3用于python 3
f2.pack_forget() to hide if you use f2.pack() to show f2.pack_forget() 隐藏,如果你使用 f2.pack() 来显示
also,还,
f2.grid_forget() to hide if you use f2.grid() to show f2.grid_forget() 隐藏,如果你使用 f2.grid() 来显示
f2.place_forget() to hide if you use f2.place() to show f2.place_forget() 隐藏,如果你使用 f2.place() 来显示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.