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évision | Révision précédente | ||
teaching:progappchim:codes_presentation [2015/02/17 11:29] – villersd | teaching:progappchim:codes_presentation [2021/01/28 17:58] (Version actuelle) – villersd | ||
---|---|---|---|
Ligne 2: | Ligne 2: | ||
===== Turtle ===== | ===== Turtle ===== | ||
+ | //Cf.// la [[https:// | ||
- | <sxh python; title : turtle-01.py> | + | <code python turtle-01.py> |
# | # | ||
- | # -*- coding: | + | # -*- coding: |
# exemple de base turtle | # exemple de base turtle | ||
Ligne 37: | Ligne 38: | ||
time.sleep(10) | time.sleep(10) | ||
- | </sxh> | + | </code> |
===== Tkinter ===== | ===== Tkinter ===== | ||
- | (Python | + | |
- | <sxh python; title : tkinter-simple-entry.py> | + | //Cf.// la [[https:// |
+ | |||
+ | <code python tkinter-simple-entry.py> | ||
# | # | ||
# -*- coding: UTF-8 -*- | # -*- coding: UTF-8 -*- | ||
Ligne 47: | Ligne 50: | ||
# lecture de 2 masses par une fenêtre tk | # lecture de 2 masses par une fenêtre tk | ||
- | from Tkinter | + | from tkinter |
fen01 = Tk() | fen01 = Tk() | ||
Ligne 68: | Ligne 71: | ||
fen01.destroy() | fen01.destroy() | ||
- | print ' | + | print(' |
+ | |||
+ | </ | ||
+ | |||
+ | ==== Canvas Tkinter : rebond d'une balle ==== | ||
+ | |||
+ | <code python anima_auto_rebond.py> | ||
+ | #! / | ||
+ | # -*- coding: utf-8 -*- | ||
+ | |||
+ | # Petit exercice utilisant la librairie graphique Tkinter | ||
+ | |||
+ | from tkinter import * | ||
+ | |||
+ | # définition des gestionnaires | ||
+ | # d' | ||
+ | |||
+ | def move(): | ||
+ | " | ||
+ | global x1, y1, vx, vy, dt, flag | ||
+ | x1, y1 = x1 +vx*dt, y1 + vy*dt | ||
+ | if x1 < 0 or x1 > 220: | ||
+ | vx=-vx | ||
+ | if y1 < 0 or y1 > 220: | ||
+ | vy = -vy | ||
+ | can1.coords(oval1, | ||
+ | if flag >0: | ||
+ | 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() | ||
+ | </ | ||
+ | |||
+ | ==== DemoTkinter ==== | ||
+ | * télécharger ici : [[http:// | ||
+ | |||
+ | ===== Matplotlib - pylab ===== | ||
+ | |||
+ | <code python simple_fonction.py> | ||
+ | # | ||
+ | # -*- coding: utf-8 -*- | ||
+ | # cosinusoïde amortie | ||
+ | |||
+ | from pylab import * | ||
+ | |||
+ | def my_func(t): | ||
+ | s1 = cos(2*pi*t) | ||
+ | e1 = exp(-t) | ||
+ | return s1*e1 | ||
+ | |||
+ | tvals = arange(0., 5., 0.05) | ||
+ | # | ||
+ | |||
+ | #show() | ||
+ | |||
+ | plot(tvals, my_func(tvals), | ||
+ | |||
+ | show() | ||
+ | </ | ||
- | </ |