Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- root = tk.Tk()
- size = input("Choose a grid size eg. 4, 7, 12 ...: ")
- size = int(size)
- def create_grid():
- d = 20
- x0 = 20
- x1 = x0 + d
- y0 = 20
- y1 = y0 + d
- for i in list(range(size)):
- for j in list(range(size)):
- row = i
- col = j
- id = cv.create_rectangle(x0, y0, x1, y1,
- tags="ALL",fill="white")
- x0 = x1
- x1 += d
- x0 = d
- x1 = x0 + d
- y0 = y1
- y1 = y0 + d
- id = cv.create_oval(24, 24, 36, 36, tags=("ALL","oval"),fill="yellow")
- def oval_move(event):
- print(event.keysym)
- cv = tk.Canvas(root, bd=5, relief="groove")
- cv.pack(fill="both", expand=True)
- cv.bind('<Configure>', create_grid())
- cv.focus_set() # probably not needed
- cv.tag_bind("oval", '<KeyPress-Down>', oval_move)
- root.mainloop()
Add Comment
Please, Sign In to add comment