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
| from tkinter import *
def avance (gd): #fonction pour faire avancer la balle
global x1,x2
x1,x2 = x1+gd, x2 + gd
can.coords(oval, x1, y1, x2, y1+30)
def retour ( ):
avance(-10)
def pousse( ):
avance(10)
#variables a traiter globalement
x1,y1,x2 ,y2= 0,150,30,180
i = 10
fen = Tk( )
fen.title("La BouBoule")
#programme principale
can = Canvas(fen, bg="dark grey", width=300, height=300)
can.grid(row=0,rowspan=3,column=1,columnspan=3)
oval = can.create_oval(x1,y1,x2,y2,fill="yellow",outline="black")
Button(fen,text="Quitter",command=fen.quit).grid(row=4 ,column=3,sticky=E)
Button(fen,text="avancer",command=pousse).grid(row=4,column=1,sticky=W)
Button(fen,text="reculer",command=retour).grid(row=5,column=1,sticky=W)
fen.mainloop( )
fen.destroy( ) |
Partager