Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from random import randrange, randint
- x=randint(0, 200)
- y=randint(0, 200)
- r=15
- mult = 1
- mult2 = 1
- mouvement = False
- def demarrer():
- global mouvement
- if mouvement == False:
- mouvement = True
- else:
- mouvement = False
- def deplace():
- global x, y, mouvement, mult, mult2
- if mouvement==True:
- if(y + 15) >= 200:
- mult *= -1
- if (y - r) <= 0 and mult==1:
- mult *= -1
- y -= mult * 5
- if (x + 15) >= 200:
- mult *= -1
- if (x - r) <= 0 and mult2==1:
- mult *= -1
- x += mult * 5
- can.coords(oval, x - mult2 * r, y - mult * r, x + mult2 * r, y + mult * r)
- fen.after(25,deplace)
- fen = Tk()
- can = Canvas(fen, bg='white', height=200, width=200)
- can.pack(side=RIGHT)
- bout1 = Button(fen,text='Quitter',command=fen.destroy)
- bout1.pack(side=BOTTOM) #Comme Christine Boutin
- boutonDemarrer = Button(fen, text='Demarrer',command=demarrer)
- boutonDemarrer.pack(side=TOP)
- c=['red','green','blue','yellow','orange']
- i=randrange(5)
- oval = can.create_oval(x-r, y-r, x+r, y+r, fill=c[i], outline=c[i])
- fen.after(50,deplace)
- fen.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment