Advertisement
savsanta

TCL/TK Tkinter Menu and SubMenu of a SubMenu Test

Nov 18th, 2018
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 2.24 KB | None | 0 0
  1. from tkinter import *
  2. root = Tk()
  3.  
  4. # Setting The Root Menu Title Bar Name
  5. PROGRAM_NAME= "BigFoot Text Editor"
  6. root.title(PROGRAM_NAME)
  7.  
  8.  
  9. my_menu_bar = Menu(root, tearoff=0)
  10. my_menu_bar.title = "Hunting Season"
  11. my_menu_bar.side = 'right'
  12. root.config(menu=my_menu_bar)
  13.  
  14. file_menu = Menu(my_menu_bar,tearoff=0)
  15.  
  16. # File Edit View and About   --- Although this shit is backwards --
  17. # Correction this shit is not backwards. When adding a menu button to the menubar \
  18. # You need to specify the menu=<xxx> portion. Even if may be redundant otherwise the stuff \
  19. # That is listed later under it dont appear.
  20. my_menu_bar.add_cascade(label='File', menu=file_menu)
  21. my_menu_bar.add_cascade(label='Edit')
  22. my_menu_bar.add_cascade(label='View')
  23. my_menu_bar.add_cascade(label='About')
  24.  
  25. #Removed After Testing For Forgotten Reason. So Ignore
  26. # Testing. So this weird thing actually gave me a submenu with the ">" under the File Menu
  27. #file_menu.add("cascade", label="Inside Test", font="Ubuntu", underline=1)
  28.  
  29. # Attempting To Add a Submenu to The File Menu 'Inside Test' cascade to the thing
  30. insideTest_submenu = Menu(file_menu, tearoff=0)  #Added as a Menu to a Menu. Get it? Attaching to parent file_menu (a cascade that acts as the file menu drop down)
  31.  
  32. # Immediately adding a "command" (ie menu item, ie menu entry) to the just created Menu within the Menu
  33. insideTest_submenu.add("command", label="Hope This Works To Add To The SubMenu", font="Ubuntu")
  34.  
  35.  
  36.  
  37. # cONVERTING THE COMMENTED ABOVE TO ADD THE SUBMENU PORTIONS
  38. file_menu.add("cascade", label="Inside Test", font="Ubuntu", underline=1, menu=inside_submenu)
  39.  
  40.  
  41. # Testing Pass 2. Result
  42. file_menu.add("command", label="Test using Command", font="Ubuntu", underline=1)
  43. file_menu.add("separator")
  44.  
  45.  
  46. file_menu.add_command(label='New', accelerator='Ctrl+N',
  47.                       compound='left', underline=0)
  48. file_menu.add_command(label='Open', accelerator='Ctrl+O',
  49.                       compound='left', underline=0)
  50. file_menu.add_command(label='Save', accelerator='Ctrl+S',
  51.                       compound='left', underline=0)
  52. file_menu.add_command(label='Save as', accelerator='Shift+Ctrl+S')
  53. file_menu.add_separator()
  54. file_menu.add_command(label='Exit', accelerator='Alt+F4')
  55.  
  56.  
  57.  
  58. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement