Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente | Prochaine révisionLes deux révisions suivantes | ||
teaching:progappchim:codes_presentation [2015/02/17 11:29] – villersd | teaching:progappchim:codes_presentation [2015/02/17 11:46] – villersd | ||
---|---|---|---|
Ligne 69: | Ligne 69: | ||
print ' | print ' | ||
+ | |||
+ | </ | ||
+ | |||
+ | rebond (erreur à corriger) | ||
+ | <sxh python; title : anima_auto_rebond.py> | ||
+ | #! / | ||
+ | # -*- coding: utf-8 -*- | ||
+ | |||
+ | # Petit exercice utilisant la librairie graphique Tkinter | ||
+ | |||
+ | from Tkinter import * | ||
+ | |||
+ | # définition des gestionnaires | ||
+ | # d' | ||
+ | |||
+ | def move(): | ||
+ | " | ||
+ | a=0.99 | ||
+ | global x1, y1, vx, vy, dt, flag | ||
+ | x1, y1 = x1 +vx*dt, y1 + vy*dt | ||
+ | if x1 < 0 or x1 > 220: | ||
+ | vx=-vx*a | ||
+ | if y1 < 0 or y1 > 220: | ||
+ | vy = -vy*a | ||
+ | can1.coords(oval1, | ||
+ | if flag > | ||
+ | fen1.after(2, | ||
+ | |||
+ | def stop_it(): | ||
+ | "arret de l' | ||
+ | global flag | ||
+ | flag =0 | ||
+ | |||
+ | def start_it(): | ||
+ | " | ||
+ | global flag | ||
+ | if flag ==0: # pour éviter que le bouton ne puisse lancer plusieurs boucles | ||
+ | flag =1 | ||
+ | | ||
+ | |||
+ | #========== Programme principal ============= | ||
+ | |||
+ | # les variables suivantes seront utilisées de manière globale : | ||
+ | x1, y1 = 40, 115 # coordonnées initiales | ||
+ | vx, vy = 10, 5 # vitesse du déplacement | ||
+ | dt=0.1 | ||
+ | flag =0 # commutateur | ||
+ | |||
+ | # Création du widget principal (" | ||
+ | fen1 = Tk() | ||
+ | fen1.title(" | ||
+ | # création des widgets " | ||
+ | can1 = Canvas(fen1, | ||
+ | can1.pack(side=LEFT, | ||
+ | oval1 = can1.create_oval(x1, | ||
+ | bou1 = Button(fen1, | ||
+ | bou1.pack(side=BOTTOM) | ||
+ | bou2 = Button(fen1, | ||
+ | bou2.pack() | ||
+ | bou3 = Button(fen1, | ||
+ | bou3.pack() | ||
+ | # démarrage du réceptionnaire d' | ||
+ | fen1.mainloop() | ||
+ | fen1.destroy() | ||
</ | </ |