Hi folks, I get back with the blog. I brought here a code that I wrote in 2009, December. I was fascinated by the electromagnetism and I wanted to try some lib to plot graphics in python.
So I do a small program that calcule the eletric force in a spire inside a magnetic fiel that grows with a 2º grade polynomial.
This was wrote in the Tkinter GUI. See some screenshots:
Now see the code:
#! /usr/bin/env python
from pylab import *
from Tkinter import *
import tkMessageBox
class GuiFramework(Frame):
def __init__(self, master=None):
Frame.__init__(self,master)
self.master.title("Maxwell.py")
self.grid(padx=10,pady=10)
self.CreateWidgets()
def CreateWidgets(self):
self.a = Label(self, text="A:")
self.a.grid(row=0, column=0)
self.b = Label(self, text="B:")
self.b.grid(row=1, column=0)
self.t = Label(self, text="T:")
self.t.grid(row=2, column=0)
self.ra = Entry(self)
self.ra.grid(row=0, column=1, columnspan=3)
self.rb = Entry(self)
self.rb.grid(row=1, column=1, columnspan=3)
self.rt = Entry(self)
self.rt.grid(row=2, column=1, columnspan=3)
self.btn = Button(self, text="Calcule", command=self.Calcule)
self.btn.grid(row=2, column=4)
self.plot = Button(self, text="Plot", command=self.Plot)
self.plot.grid(row=0, column=4)
def Calcule(self):
r = 2*int(self.ra.get())*int(self.rt.get()) + int(self.rb.get())
tkMessageBox.showinfo("Text", "Eletric Force: %d" % r)
def Plot(self):
t = arange(0.0, 10.0, 0.01)
s = 2*int(self.ra.get())*t + int(self.rb.get())
plot(t, s, linewidth=1.0)
title('F(t)= 2.t.A + B')
grid(True)
show()
if __name__ == "__main__":
print "\n \n Maxwell will go calculate the eletric force necessary to put a ring in equillibrium second the Faraday/Lenz law. The magnetic flow grow with a polinomiun equation:\n\n at^2 + bt + c "
guiFrame = GuiFramework()
guiFrame.mainloop()