Advertisement
c0d3dsk1lls

Simple menubar in python CodedSkills.net

Aug 2nd, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.85 KB | None | 0 0
  1. #CREATE A MENUBAR
  2. from tkinter import *
  3. #---------------------------------#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4. def openFile():                   #                      +#
  5.     print("File has been opened!")#                      +#
  6.     #-----------------------------#                      +#
  7. def saveFile():                   #                      +#
  8.     print("File has been saved!") #                      +#
  9.     #-----------------------------#                      +#
  10. def cut():                        #                      +#
  11.     print("You cut some text!")   #                      +#
  12.     #-----------------------------#                      +#
  13. def copy():                       #+++++++++++++++++++++++#               +       _______
  14.     print("You copied some text!")#                +                              +  ____
  15.     #-----------------------------#                +---------CODEDSKILLS.NET!-----+----__
  16. def paste():                      #                +                              +  
  17.     print("You pasted some text!")#                +                              +
  18. #---------------------------------#----------------+----------+-------------------+----------------------
  19. #FILE MENU--------------------------------------------#-------++++++++++++        +
  20. window = Tk()                                         #       +-----------------  +
  21. menubar = Menu(window)                                #-------++++++++++++        +
  22. window.config(menu=menubar)                           #       +-----------------  +
  23. fileMenu = Menu(menubar,tearoff=0)                    #-------++++++++++++        +
  24. menubar.add_cascade(label="File",menu=fileMenu)       #       +-----------------  +
  25. fileMenu.add_command(label="Open",command=openFile)   #-------++++++++++++        +
  26. fileMenu.add_command(label="Save",command=saveFile)   #       +-----------------  +
  27. fileMenu.add_separator()                              #-------++++++++++++        +
  28. fileMenu.add_command(label="Exit",command=quit)       #       +-----------------  +
  29. #-----------------------------------------------------#-------+++++++++++++++++++++------------------------
  30. #EDIT MENU----------------------------------------------------+-------------------+
  31. editMenu = Menu(menubar                 ,tearoff=0)          # add spacing to make ur code look nicer
  32. menubar.add_cascade   (label="Edit"     ,menu=editMenu)      #+-----------------  +
  33. editMenu.add_cascade  (label="Cut"      ,command=cut)        #
  34. editMenu.add_cascade  (label="Copy"     ,command=       copy)# spacing is fine in some spots.
  35. editMenu.add_cascade  (label="Paste"    ,command=paste)
  36. window.mainloop       ()
  37.  
  38. #------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement