Python:删除 TKinter 框架

编程入门 行业动态 更新时间:2024-10-24 19:29:45
本文介绍了Python:删除 TKinter 框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想在单击特定按钮时从我的界面中删除一个框架.

I want to remove a frame from my interface when a specific button is clicked.

这是调用的回调函数

def removeMyself(self):
    del self

但是,它不会自行删除.我可能只是在 python 中删除对象而不更新界面?

However, it doesn't remove itself. I'm probably just deleting the object in python without updating the interface ?

谢谢

更新

self.itemFrame = tk.Frame(parent)
self.itemFrame.pack(expand=False, side=tk.TOP)

removeB = tk.Button(self.itemFrame, text="Remove", width=10, command=self.removeIsosurface)

def removeIsosurface(self):
    self.itemFrame.Destroy()

错误信息:

AttributeError: Frame instance has no attribute 'Destroy'

推荐答案

要删除,调用 frm.pack_forget()frm.grid_forget() 取决于是否框架被打包或网格化.

To remove, call either frm.pack_forget() or frm.grid_forget() depending on whether the frame was packed or grided.

然后调用 frm.destroy() 如果您不打算再次使用它,或者在您想再次显示时保留参考并重新打包或重新网格.

Then call frm.destroy() if you aren't going to use it again, or hold onto the reference and repack or regrid when you want to show it again.

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

更多推荐

[db:关键词]

本文发布于:2023-04-30 07:39:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1391352.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:框架   Python   TKinter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!