Guest User

Untitled

a guest
May 26th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import tkinter as tk
  2. root = tk.Tk()
  3. size = input("Choose a grid size eg. 4, 7, 12 ...: ")
  4. size = int(size)
  5. def create_grid():
  6. d = 20
  7. x0 = 20
  8. x1 = x0 + d
  9. y0 = 20
  10. y1 = y0 + d
  11. for i in list(range(size)):
  12. for j in list(range(size)):
  13. row = i
  14. col = j
  15. id = cv.create_rectangle(x0, y0, x1, y1,
  16. tags="ALL",fill="white")
  17. x0 = x1
  18. x1 += d
  19. x0 = d
  20. x1 = x0 + d
  21. y0 = y1
  22. y1 = y0 + d
  23. id = cv.create_oval(24, 24, 36, 36, tags=("ALL","oval"),fill="yellow")
  24. def oval_move(event):
  25. print(event.keysym)
  26. cv = tk.Canvas(root, bd=5, relief="groove")
  27. cv.pack(fill="both", expand=True)
  28. cv.bind('<Configure>', create_grid())
  29. cv.focus_set() # probably not needed
  30. cv.tag_bind("oval", '<KeyPress-Down>', oval_move)
  31. root.mainloop()
Add Comment
Please, Sign In to add comment