Python Tkinter 编辑菜单窗口 [英] Python Tkinter Edit Menu Window

查看:35
本文介绍了Python Tkinter 编辑菜单窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编辑菜单窗口.我如何编辑它?

I'm trying to edit Menu window. How can i edit it?

这适用于 Windows.

This is for Windows.

from tkinter import *

Window = Tk()

MB = Menu(Window)
Window.config(menu=MB)

Menubar = Menu(MB)
MB.add_cascade(label="File", menu=Menubar)
Menubar.add_command(label="New File")

#Btn1 = Button(Menubar, width=20, text="Button").pack() #I failed.

Window.mainloop()

我试过 Btn1 = Button(Menubar, width=20, text="Button").pack()但是这个不行.

I tried Btn1 = Button(Menubar, width=20, text="Button").pack() But this one couldn't work.

推荐答案

您不能向菜单添加任意小部件.要将项目添加到菜单,您必须使用 Menu 对象上可用的以下功能之一:

You cannot add arbitrary widgets to a menu. To add items to a menu you must use one of the following functions available on the Menu object:

  • 添加
  • add_command
  • add_cascade
  • add_checkbutton
  • add_radiobutton
  • add_separator

要添加文本标签,您可以使用 add_command 并将 command 属性设置为 None.

To add a textual label you can use add_command and set the command attribute to None.

所有这些都与菜单小部件定义本身一起记录,并且几乎在任何包含小部件文档的网站上都有记录.

All of these are documented with the Menu widget definition itself, and on just about any site that includes widget documentation.

这篇关于Python Tkinter 编辑菜单窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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