making multiple menu's in tkinter

旧城冷巷雨未停 提交于 2021-02-11 18:11:18

问题


Tried searching for this and could not find a suitable answer. I know we can do the following to create a menu to the root window in tkinter

menu = Menu(root)
some_menu = Menu(menu, ....)
some_menu.add_command(label = some text, command = some command) 
....
menu.add_cascade(label = some title, menu = some_menu)
root.config(menu = menu)

now let's say that we passed some_menu to the root config instead then it would display the cascade menu's options / children horizontally across the top bar of the the tkinter window where the menu's appear and we could make multiple menu's this way by creating sub menu's of these options but this seems a bit convoluted.

That being said is there a way to create multiple menu's beside each other? I tried creating a new menu as above and just passing the new menu to root.config

another_menu = Menu(root)
options = Menu(another_menu, ....)
options.add_command(label = some label, command = some command)
another_menu.add_cascade(label = some text, menu = options)
root.config(menu = another_menu)

as well however the program / script gets stuck whenever this is added and doesn't run I'm assuming that's some sort of memory leak? Which would make sense, but I don't see another way to do this.


回答1:


You can have only a single menubar at the top of an application. This menubar can have as many child ("cascade") menus on it that will fit on the screen. On some platforms, you can also add commands to the top menubar, but from a usability standpoint that is a bad idea.



来源:https://stackoverflow.com/questions/29247314/making-multiple-menus-in-tkinter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!