在 tkinter 中制作多个菜单 [英] making multiple menu's in tkinter

查看:51
本文介绍了在 tkinter 中制作多个菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试搜索此问题,但找不到合适的答案.我知道我们可以执行以下操作来为 tkinter 中的根窗口创建一个菜单

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)

现在假设我们将 some_menu 传递给根配置,然后它将在菜单出现的 tkinter 窗口的顶部栏上水平显示级联菜单的选项/子项,我们可以通过创建子菜单以这种方式制作多个菜单这些选项的菜单,但这似乎有点令人费解.

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.

话虽如此,有没有办法在彼此旁边创建多个菜单?我尝试像上面一样创建一个新菜单,然后将新菜单传递给 root.config

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.

推荐答案

在应用程序的顶部只能有一个菜单栏.这个菜单栏上可以有尽可能多的子(级联")菜单,以适应屏幕.在某些平台上,您还可以向顶部菜单栏添加命令,但从可用性的角度来看,这是个坏主意.

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.

这篇关于在 tkinter 中制作多个菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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