Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. # Simple enough, just import everything from tkinter.
  2. from tkinter import *
  3.  
  4.  
  5. # Here, we are creating our class, Window, and inheriting from the Frame
  6. # class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__)
  7. class Window(Frame):
  8.  
  9. # Define settings upon initialization. Here you can specify
  10. def __init__(self, master=None):
  11.  
  12. # parameters that you want to send through the Frame class.
  13. Frame.__init__(self, master)
  14.  
  15. #reference to the master widget, which is the tk window
  16. self.master = master
  17.  
  18. #with that, we want to then run init_window, which doesn't yet exist
  19. self.init_window()
  20.  
  21.  
  22. #Creation of init_window
  23. def init_window(self):
  24.  
  25. # changing the title of our master widget
  26. self.master.title("PCD")
  27.  
  28. # allowing the widget to take the full space of the root window
  29. self.pack(fill=BOTH, expand=1)
  30.  
  31. # creating a menu instance
  32. menu = Menu(self.master)
  33. self.master.config(menu=menu)
  34.  
  35. # create the file object)
  36. file = Menu(menu)
  37.  
  38. file.add_command(label="New")
  39. file.add_command(label="Open")
  40. file.add_command(label="Save")
  41. file.add_command(label="Save As")
  42.  
  43. # adds a command to the menu option, calling it exit, and the
  44. # command it runs on event is client_exit
  45. file.add_command(label="Exit", command=self.client_exit)
  46.  
  47. #added "file" to our menu
  48. menu.add_cascade(label="File", menu=file)
  49.  
  50. # create the file object)
  51. edit = Menu(menu)
  52.  
  53. # adds a command to the menu option, calling it exit, and the
  54. # command it runs on event is client_exit
  55. edit.add_command(label="Undo")
  56.  
  57. #added "edit" to our menu
  58. menu.add_cascade(label="Edit", menu=edit)
  59.  
  60.  
  61. def client_exit(self):
  62. exit()
  63.  
  64.  
  65. # root window created. Here, that would be the only window, but
  66. # you can later have windows within windows.
  67. root = Tk()
  68.  
  69. root.geometry("450x450")
  70.  
  71. #creation of an instance
  72. app = Window(root)
  73.  
  74. #mainloop
  75. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement