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
| from tkinter import *
fenetre=Tk()
fenetre.geometry("700x500")
x=350
y=250
l=[]
def gauche():
global x,y,l
canevas.create_line(x,y,x-10,y,fill="black",width=4)
l.append("g")
x=x-10
def droite():
global x,y,l
canevas.create_line(x,y,x+10,y,fill="black",width=4)
l.append("d")
x=x+10
def bas():
global x,y,l
canevas.create_line(x,y,x,y-10,fill="black",width=4)
l.append("b")
y=y-10
def haut():
global x,y,l
canevas.create_line(x,y,x,y+10,fill="black",width=4)
l.append("h")
y=y+10
canevas=Canvas(fenetre,width=500,height=400,bg="#FEFEFE")
canevas.pack(padx=5,pady=5)
bouton_gauche = Button(fenetre, text="Gauche", command=gauche())
bouton_gauche.pack(side=LEFT)
bouton_droite = Button(fenetre, text="Droite", command=droite())
bouton_droite.pack(side=LEFT)
bouton_haut = Button(fenetre, text="Haut", command=haut())
bouton_haut.pack(side=LEFT)
bouton_bas = Button(fenetre, text="Bas", command=bas())
bouton_bas.pack(side=LEFT)
bouton_quitter = Button(fenetre, text="Quitter", command=fenetre.quit)
bouton_quitter.pack(side=BOTTOM)
fenetre.mainloop()
fenetre.destroy() |
Partager