python实例代码之禁用菜单项

发布时间:2019-12-23编辑:脚本学堂
本文分享一个python实例代码,学习禁用菜单项的操作方法,有需要的朋友参考下吧。

python禁用菜单项的代码,如下:

#!/bin/python
from Tkinter import *

class TestMenu:
    def __init__(self, master):
  self.master = master
  self.menubar = Menu(self.master)

        self.cmdmenu = Menu(self.menubar)
        self.cmdmenu.add_command(label="Undo")
        self.cmdmenu.entryconfig(1, state=DISABLED)

        self.unused = Menu(self.menubar)

        self.menubar.add_cascade(label="Button Command", menu=self.cmdmenu)

  self.top = Toplevel(menu=self.menubar, width=500, relief=RAISED,
                            borderwidth=2)
def main():
    root = Tk()
    root.withdraw()
    app = TestMenu(root)
    root.mainloop()

if __name__ == '__main__':
    main()