Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def elem(i, j):
- canvas.create_oval((i + 1) * 25, (j + 1) * 25, (i + 2) * 25, (j + 2) * 25, fill = "green")
- def snake():
- global table_x, table_y
- i = 0
- while i < len(table_x):
- elem(table_x[i], table_y[i])
- i+=1
- def all():
- snake()
- canvas.update()
- def left(event):
- global v_x, v_y
- v_x = -1
- v_y = 0
- def right(event):
- global v_x, v_y
- v_x = 1
- v_y = 0
- def down(event):
- global v_x, v_y
- v_x = 0
- v_y = -1
- def up(event):
- global v_x, v_y
- v_x = 0
- v_y = 1
- from tkinter import *
- import time
- root = Tk()
- canvas = Canvas(root, height = (20+2) * 25, width = (30 + 2) *25)
- canvas.pack()
- root.bind("<Left>", left)
- root.bind("<Right>", right)
- root.bind("<Down>", down)
- root.bind("<Up>", up)
- table_x = [5, 6, 7, 8]
- table_y = [3, 3, 3, 3]
- win = True
- v_x = -1
- v_y = 0
- while win:
- table_x = [table_x[0] + v_x] + table_x
- table_y = [table_y[0] + v_y] + table_y
- table_x.pop(-1)
- table_y.pop(-1)
- all()
- time.sleep(0.1)
- canvas.delete('all')
- all()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement