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
| 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 droite( ): #fonction pour aller a droite
avance(30)
def gauche( ): #fonction pour aller a gauche
avance(-30)
def pousse( ):
global x1,x2
droite
if x2 <= 300 and x2 >= 30:
gauche
if x1 >= 0 and x1 <= 270:
droite
#variables a traiter globalement
x1,y1,x2 ,y2= 0,150,30,180
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="poupousse",command=pousse).grid(row=4,column=1,sticky=W)
fen.mainloop( )
fen.destroy( ) |
Partager