Advertisement
virtualideaz

Python Menu Sample

Oct 23rd, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. from tkinter import *
  2. def donothing():
  3.    filewin = Toplevel(root)
  4.    #Toplevel = is a widget if you want to declare a separate window
  5.    button = Button(filewin, text="Do nothing button")
  6.    button.pack()
  7.  
  8. #tearoff option should be declared in default
  9. #tearoff default value is 0
  10. root = Tk()
  11. menubar = Menu(root)
  12. filemenu = Menu(menubar, tearoff=0)
  13. filemenu.add_command(label="New", command=donothing)
  14. filemenu.add_command(label="Open", command=donothing)
  15. filemenu.add_command(label="Save", command=donothing)
  16. filemenu.add_command(label="Save as...", command=donothing)
  17. filemenu.add_command(label="Close", command=donothing)
  18.  
  19. filemenu.add_separator()
  20.  
  21. filemenu.add_command(label="Exit", command=root.quit)
  22. menubar.add_cascade(label="File", menu=filemenu)
  23. #end of the "File" menubar
  24.  
  25. #declare the next menu
  26. #nameofthemenubar = Menu(menubar, tearoff = 0)
  27. #after declaring the menubar itself, add the contents
  28. editmenu = Menu(menubar, tearoff=0)
  29. editmenu.add_command(label="Undo", command=donothing)
  30.  
  31. editmenu.add_separator()
  32.  
  33. editmenu.add_command(label="Cut", command=donothing)
  34. editmenu.add_command(label="Copy", command=donothing)
  35. editmenu.add_command(label="Paste", command=donothing)
  36. editmenu.add_command(label="Delete", command=donothing)
  37. editmenu.add_command(label="Select All", command=donothing)
  38.  
  39. menubar.add_cascade(label="Edit", menu=editmenu)
  40.  
  41.  
  42. #declare the next menu
  43. #nameofthemenubar = Menu(menubar, tearoff = 0)
  44. #after declaring the menubar itself, add the contents
  45. helpmenu = Menu(menubar, tearoff=0)
  46. helpmenu.add_command(label="Help Index", command=donothing)
  47. helpmenu.add_command(label="About...", command=donothing)
  48. menubar.add_cascade(label="Help", menu=helpmenu)
  49.  
  50. root.config(menu=menubar)
  51. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement