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
| from tkinter import *
from math import sqrt
def distance(x1,y1,x2,y2):
"Distance séparant les points x1,y1 et x2,y2"
d = sqrt((x2-x1)**2 + (y2-y1)**2)
return d
def forceG(m1,m2,di):
"Force de gravitation s'exerçant entre m1 et m2 pour une distance di"
return m1*m2*6.67e-11/di**2
def pointeur(event):
global x,y
x[n],y[n] = event.x,event.y
can.coords(astre[n],x[n]-10,y[n]-10,x[n]+10,y[n]+10)
di = distance(x[0],y[0],x[1],y[1])
diA = di*1e9
f = forceG(m1,m2,diA)
valDis.configure(text="Distance = "+str(diA)+" m")
valFor.configure(text="Force = "+str(f)+" N")
def astre1():
global n
n = 0
def astre2():
global n
n = 1
m1,m2 = 6e24,6e24
x,y = [20.,50],[20.,20]
astre = [0]*2
n = 0
fen = Tk()
fen.title("Gravitation selon Newton")
valDis = Label(fen,text="Distance")
valDis.grid(row=1,column=1,padx=10,sticky=W)
valFor = Label(fen,text="Force")
valFor.grid(row=2,column=1,padx=10,sticky=W)
can = Canvas(fen,bg="light grey",width=300,height=200)
can.grid(row=0,column=1,columnspan=2,padx=10,pady=10)
can.bind("<Button-1>",pointeur)
astre[0] = can.create_oval(x[0]-10,y[0]-10,x[0]+10,y[0]+10,fill="red",width =2)
astre[1] = can.create_oval(x[1]-10,y[1]-10,x[1]+10,y[1]+10,fill="blue",width =2)
Button(fen,text="Astre 1",command=astre1).grid(row=0,column=3,pady=10,sticky=N)
Button(fen,text="Astre 2",command=astre2).grid(row=0,column=3,pady=40,sticky=N)
fen.mainloop() |
Partager