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
|
# -*- coding:utf-8 -*-
from Tkinter import *
from math import *
#formule distance entre deux points sqrt((x2-x1)**2+(y2-y1)**2)
#formule force gravitationnelle (6.67*10**(-11))*masse1*masse2/distance**2
#déplacement des astres
def avance(event):
global x1,y1,x2,y2
global masse1,masse2
global astre
astre=astre1
if astre==astre1:
x1,y1=event.x,event.y
can.coords(astre1,x1,y1,x1+30,y1+30)
if astre==astre2:
x2,y2=event.x,event.y
can.coords(astre2,x2,y2,x2+40,y2+40)
Label(fen,text=astre,fg='green').grid(row=14,column=2)
distance=sqrt((x2-x1)**2+(y2-y1)**2)
force=(6.67*10**(-11))*masse1*masse2/distance**2
#affichage de la distance entre les deux astres
Label(fen,text="Distance entre les deux astres: "+str(distance),fg='blue').grid(row=11,column=2)
#affichage de la force de gravitation
Label(fen,text="Force de gravitation entre les deux astres: "+str(force),fg='dark blue').grid(row=12,column=2)
Label(fen,text="Masse de l'astre 1: "+str(masse1)+" masse de l'astre 2: "+str(masse2)).grid(row=13,column=2)
#gesdtionnaire d'événement astre 1
def astre1():
def astre2():
#varoable global
x1,y1=10,10
x2,y2=20,20
masse1=100
masse2=250
#pgm principal
fen=Tk()
fen.title("astre mouvant")
#widget esclave
can=Canvas(fen,width=400,height=400,bg='light grey')
astre1=can.create_oval(x1,y1,x1+30,y1+30,fill='red',width=2)
astre2=can.create_oval(x2,y2,x2+45,y2+45,fill='light yellow',width=2)
can.grid(column=2,row=1,rowspan=10)
can.bind("<Button-1>",avance)
#bouton pour astre 1
Button(fen,text="astre1",command=astre1).grid(column=1)
Button(fen,text="astre2",command=astre2).grid(column=1)
fen.mainloop() |
Partager