python实现禁用菜单的功能,代码如下:
#!/bin/python from Tkinter import * class TestMenu: def __init__(self, master): self.master = master self.menubar = Menu(self.master) self.radmenu = Menu(self.menubar) self.radmenu.add_radiobutton(label='A') self.radmenu.add_radiobutton(label='B') self.radmenu.add_radiobutton(label='C') self.radmenu.add_radiobutton(label='D') self.radmenu.add_radiobutton(label='E') self.radmenu.add_radiobutton(label='F') self.radmenu.add_radiobutton(label='H') self.radmenu.add_radiobutton(label='L') self.radmenu.add_radiobutton(label='Z') self.menubar.add_cascade(label="Radiobutton Menu", menu=self.radmenu) self.menubar.entryconfig(1, state=disabled) 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()
python禁用菜单功能,效果图如下: