1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| from tkinter import*
import time
DEBUG=True
def debug(s):
if DEBUG : print(s)
def JJA_Play_Mouv(event):
touche=event.keysym
global x,y,w,z,m1,m2,m3,m4
if(touche=="z"):
if(w!=0):
a=Can.create_rectangle(x,w,y,z,outline='light blue', fill="light blue")
x=x
w=w-10
y=y
z=z-10
Can.coords(moto1,x,w,y,z)
if(touche=="s"):
if(z!=hauteur):
a=Can.create_rectangle(x,w,y,z,outline='light blue', fill="light blue")
x=x
w=w+10
y=y
z=z+10
Can.coords(moto1,x,w,y,z)
if(touche=="q"):
if(x!=0):
a=Can.create_rectangle(x,w,y,z,outline='light blue', fill="light blue")
x=x-10
w=w
y=y-10
z=z
Can.coords(moto1,x,w,y,z)
if(touche=="d"):
if(y!=largeur):
a=Can.create_rectangle(x,w,y,z,outline='light blue', fill="light blue")
x=x+10
w=w
y=y+10
z=z
Can.coords(moto1,x,w,y,z)
if(touche=="o"):
if(m4!=0):
b=Can.create_rectangle(m1,m2,m3,m4,outline='light salmon', fill="light salmon")
m1=m1
m2=m2-10
m3=m3
m4=m4-10
Can.coords(moto2,m1,m2,m3,m4)
if(touche=="l"):
if(m2!=hauteur):
b=Can.create_rectangle(m1,m2,m3,m4,outline='light salmon', fill="light salmon")
m1=m1
m2=m2+10
m3=m3
m4=m4+10
Can.coords(moto2,m1,m2,m3,m4)
if(touche=="k"):
if(m1!=0):
b=Can.create_rectangle(m1,m2,m3,m4,outline='light salmon', fill="light salmon")
m1=m1-10
m2=m2
m3=m3-10
m4=m4
Can.coords(moto2,m1,m2,m3,m4)
if(touche=="m"):
if(m3!=largeur):
b=Can.create_rectangle(m1,m2,m3,m4,outline='light salmon', fill="light salmon")
m1=m1+10
m2=m2
m3=m3+10
m4=m4
Can.coords(moto2,m1,m2,m3,m4)
fen=Tk()
fen.title("ReTroN")
largeur=1200
hauteur=650
w=10
x=10
y=20
z=20
m1=largeur-20
m2=hauteur-20
m3=largeur-10
m4=hauteur-30
Can= Canvas(fen,width=largeur, height=hauteur, bg="white")
moto1=Can.create_rectangle(w,x,y,z,outline="blue", fill="sky blue")
moto2=Can.create_rectangle(m1,m2,m3,m4, outline="red", fill="orange")
Can.focus_set()
Can.bind('<Key>',JJA_Play_Mouv)
Can.pack(padx =5, pady =5)
Bou1=Button(fen, text='Rage Quit', command=fen.destroy)
Bou1.pack(side=LEFT,padx=5,pady=5)
fen.mainloop() |
Partager