Sylronika自用

电子轨道图像很重要

xarr=[]
yarr=[]

from tkinter import *    
import matplotlib.pyplot as plt
gui=Tk(className='Flugbahn eines Elektrons')
gui.minsize(700,500)
gui['bg']='lightgreen'

lab_spannung=Label(gui, text='Spannung: ', bg='lightgreen')
lab_platte=Label(gui, text='Plattenabstand: ', bg='lightgreen')
lab_v=Label(gui, text='Startgeschwindigkeit: ', bg='lightgreen')
lab_laenge=Label(gui, text='Laenge des Kondensators: ', bg='lightgreen')
lab_s=Label(gui, text='Schrittweite: ', bg='lightgreen')

lab_spannung.place(x=150,y=50)
lab_platte.place(x=150,y=80)
lab_v.place(x=150,y=110)
lab_laenge.place(x=150,y=140)
lab_s.place(x=150,y=170)


inp_spannung=Entry(gui)
inp_platte=Entry(gui)
inp_v=Entry(gui)
inp_laenge=Entry(gui)
inp_s=Entry(gui)

inp_spannung.place(x=300,y=50)
inp_platte.place(x=300,y=80)
inp_v.place(x=300,y=110)  
inp_laenge.place(x=300,y=140)
inp_s.place(x=300,y=170)


def berechnen():

const_e=1.6022e-19 # Elementarladung
const_m=9.00e-31 # Masse des Elektrons

u=inp_spannung.get()
d=inp_platte.get()
v0=inp_v.get()
l=inp_laenge.get()
s=inp_s.get()

u=float(u)    #确保为整数
d=float(d)
v0=float(v0)
l=float(l)
s=float(s)

x=0 # Startwert fuer x
xarr.clear()
yarr.clear()

while x<l:
      y=-0.5*(const_e/const_m)*(u/d)*(x/v0)**2
      print(x,y)
      xarr.append(x)
      yarr.append(y)
      x+=s

plt.plot(xarr,yarr)
plt.savefig('C:/temp/el_im_feld.jpg')
plt.show()

def beenden():
  gui.destroy()

def externe_Daten():
   file1=open('c:/temp/elektron_ext.txt','w')
   for i in range(len(xarr)):
      file1.write(str(xarr[i])+','+str(yarr[i])+'\n')
   file1.close()

   file2=open('c:/temp/elektron_ext.html','w')
   file2.write('<html><body><table border="1" bgcolor="pink">')
   for i in range(len(xarr)):
      file2.write('<tr><td>'+str(xarr[i])+'</td><td>'+str(yarr[i])+'</td></tr>')
   file2.write('</table></body></html>')
   file2.close()

rechnen=Button(gui, text='Berechnen', command=berechnen)
ende=Button(gui, text='Ende', command=beenden)
extern=Button(gui, text='Extern', command=externe_Daten)

rechnen.place(x=150,y=220)
ende.place(x=300,y=220)
extern.place(x=235,y=220)

gui.mainloop()
上一篇:在超图添加其他图层


下一篇:学习面试题Day08