Advertisement
furas

turtle with menu and button using tkinter

Apr 16th, 2017
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # screenshot: http://imgur.com/SIISwwA
  4.  
  5. import turtle
  6.  
  7. def hello():
  8.     print('Hello!')
  9.  
  10. def draw():
  11.     turtle.forward(50)
  12.     turtle.left(30)
  13.     turtle.forward(50)
  14.     turtle.left(30)
  15.  
  16. # access to tkinter - tk & root
  17. # instead of standard
  18. # import tkinter as tk
  19. # root = tk.Tk()  
  20. tk = turtle.TK
  21. root = turtle.getscreen()._root
  22.  
  23. #root.geometry('500x500')
  24. turtle.setup(width=500, height=500)
  25.  
  26. # create a toplevel menu
  27. menubar = tk.Menu(root)
  28. root.config(menu=menubar)
  29.  
  30. # create submenu
  31. filemenu = tk.Menu(menubar, tearoff=0)
  32. filemenu.add_command(label="Open", command=hello)
  33. filemenu.add_command(label="Save", command=hello)
  34. filemenu.add_command(label="Close", command=root.destroy)
  35. menubar.add_cascade(label="File", menu=filemenu)
  36.  
  37. # create button
  38. button = tk.Button(root, text="Draw", command=draw)
  39. # add button to window
  40. button.pack()
  41.  
  42. #turtle.done()
  43. #turtle.mainloop()
  44. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement