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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
from Tkinter import *
#Fonctions
def distance(x, y, x1, y1) :
d = ((x-x1)**2+(y-y1)**2)
chaine2.configure(text='La distance est de ' + str(d) + '*10^6 m')
return d
def force(di) :
global mp, mg
G = 6.67*(10**-11)
f = G*mp*mg/di
return f
#Procédure générale de déplacement
def deplacement(event) :
global x, y
x[n] = event.x
y[n] = event.y
can1.coords(oval[n], x[n], y[n], x[n]+r[n], y[n]+r[n])
di = distance(x[0], y[0], x[1], y[1])
forc = force(di)
chaine.configure(text='Force=' + str(forc) + ' Newtons')
#Les variables suivantes seront globales
#Coordonnées initiales
x = [400., 10.]
y = [300., 10.]
oval = [0, 1]
#Masses des planètes
mp, mg = 10**15, 10**24
r = [30, 10]
n = 1
#Création du widget principal
fen1 = Tk()
fen1.title('La gravitation newtonienne')
#Création des widgets esclaves
#Fenêtre
can1 = Canvas(fen1, width =800, height =400, bg="light yellow")
can1.bind("<Button-1>", deplacement)
can1.pack()
#Planètes
oval1 = can1.create_oval(x[1], y[1], x[1]+10, y[1]+10, width=2, fill='red')
oval0 = can1.create_oval(x[0], y[0], x[0]+30, y[0]+30, width=2, fill='blue')
#Textes
choix = Frame(fen1).pack()
Radiobutton(choix, text='Planète', var=n, value = 0).pack()
Radiobutton(choix, text='Satellite', var=n, value = 1).pack()
chaine = Label(fen1)
chaine.pack()
chaine2 = Label(fen1)
chaine2.pack()
#Démarrage du réceptionnaire d'événements
fen1.mainloop() |
Partager