Python Tkinter清除帧 [英] Python Tkinter clearing a frame

查看:25
本文介绍了Python Tkinter清除帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试清除 tkinter 中的一个框架,以便可以写入新内容(刷新信息),但我无法做到.我知道这些

I am trying to clear out a frame in the tkinter so that the new contents can be written (refresh information) but i could not manage to do it. I am aware of these

frame.destroy()
frame.pack_forget()
frame.grid_forget()

但是 frame.destroy() 将完全删除框架.而另外两个也无法给我想要的结果.我需要的只是清除框架中的每个项目,但框架本身会保留.有办法吗?

but frame.destroy() will totally remove the frame. And the other two also could not give me the result i want.What i need is just to clear up every items in the frame but the frame itself will stay. Is there anyway to do it?

推荐答案

pack_forgetgrid_forget 只会从视图中删除小部件,不会破坏它们.如果您不打算重复使用这些小部件,那么您唯一真正的选择就是使用 destroy 方法销毁它们.

pack_forget and grid_forget will only remove widgets from view, it doesn't destroy them. If you don't plan on re-using the widgets, your only real choice is to destroy them with the destroy method.

要做到这一点,您有两种选择:单独销毁每个框架,或者销毁将导致其所有子项都被销毁的框架.后者通常是最简单和最有效的.

To do that you have two choices: destroy each one individually, or destroy the frame which will cause all of its children to be destroyed. The latter is generally the easiest and most effective.

既然您声称不想破坏容器框架,请创建一个辅助框架.让这个辅助框架成为你想要删除的所有小部件的容器,然后把这个框架放在你不想想要销毁的父框架中.然后,只需销毁这一帧,所有内部小部件都会随之销毁.

Since you claim you don't want to destroy the container frame, create a secondary frame. Have this secondary frame be the container for all the widgets you want to delete, and then put this one frame inside the parent you do not want to destroy. Then, it's just a matter of destroying this one frame and all of the interior widgets will be destroyed along with it.

这篇关于Python Tkinter清除帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆