问题描述
限时送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:关键词]
发布评论