简体   繁体   English

Tkinter OptionMenu 删除

[英]Tkinter OptionMenu delete

Is there a way to completely delete OptionMenu from your grid widget?有没有办法从网格小部件中完全删除 OptionMenu ? Without any side module.没有任何侧面模块。

I've tried some approaches, nothing worked:我尝试了一些方法,没有任何效果:

# forget from grid
option_menu.grid_forget()

# reset to default
option_menu = OptionMenu(master, None, None)

# delete items
option_menu['menu'].delete(0, 'end')

If you want to remove the widget from view you have two choices:如果您想从视图中删除小部件,您有两种选择:

The first choice is to call the "forget" method for whichever geometry manager you're using (either grid_forget() , pack_forget() , or place_forget() ).第一个选择是为您使用的任何几何管理器调用“忘记”方法( grid_forget()pack_forget()place_forget() )。 This will cause the widget to be removed from the window, but the widget will still exist.这将导致小部件从窗口中删除,但小部件仍将存在。 You can make it reappear by calling grid , pack , or place .您可以通过调用gridpackplace使其重新出现。

If you want to completely throw away the widget, you can call the destroy method: option_menu.destroy() .如果你想完全扔掉小部件,你可以调用destroy方法: option_menu.destroy() This will both remove it from view and also destroy the underlying widget.这既会从视图中删除它,也会破坏底层的小部件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM