1#! /usr/bin/env python 2 3"""Play with the new Tk 8.0 toplevel menu option.""" 4 5from Tkinter import * 6 7class App: 8 9 def __init__(self, master): 10 self.master = master 11 12 self.menubar = Menu(self.master) 13 14 self.filemenu = Menu(self.menubar) 15 16 self.filemenu.add_command(label="New") 17 self.filemenu.add_command(label="Open...") 18 self.filemenu.add_command(label="Close") 19 self.filemenu.add_separator() 20 self.filemenu.add_command(label="Quit", command=self.master.quit) 21 22 self.editmenu = Menu(self.menubar) 23 24 self.editmenu.add_command(label="Cut") 25 self.editmenu.add_command(label="Copy") 26 self.editmenu.add_command(label="Paste") 27 28 self.helpmenu = Menu(self.menubar, name='help') 29 30 self.helpmenu.add_command(label="About...") 31 32 self.menubar.add_cascade(label="File", menu=self.filemenu) 33 self.menubar.add_cascade(label="Edit", menu=self.editmenu) 34 self.menubar.add_cascade(label="Help", menu=self.helpmenu) 35 36 self.top = Toplevel(menu=self.menubar) 37 38 # Rest of app goes here... 39 40def main(): 41 root = Tk() 42 root.withdraw() 43 app = App(root) 44 root.mainloop() 45 46if __name__ == '__main__': 47 main() 48