OK, so first of all, this is my first attempt at a GUI, so please pardon any extra confusion or glaringly obvious mistakes (not to mention plain, flat-out newbiness). :)
I'm trying to create a GUI in Tkinter for Python 2 that takes the wavelength (in m/wave) of EM radiation, and calculates both the frequency and energy of the wave, in Hz and energy-unit/quantum, respectively.
I want to be able to choose the energy-unit by pressing buttons in tk, but for now, I'm starting with Joules.
The flow will look like this: wavelength is passed into entry widget, one of x buttons are pressed to choose what unit to return energy in, and the frequency and energy are then returned.
I've done this much so far
from __future__ import division
import Tkinter as tk
mainwin = tk.Tk()
mainwin.title("Wave1")
#Input label
v = tk.IntVar()
ent = tk.Entry(mainwin, textvariable = v)
ent.pack()
wavelength = v.get()
def Joules(wavelength):
global wavelength
freq = (299792458)/wavelength
Energy = 6.62606957E-34 * freq
print freq
print Energy
b1 = tk.Button(mainwin, text="Joules", command= lambda wavelength: Joules(wavelength))
b1.pack()
mainwin.mainloop()
I'm really not sure where to go from here, so if someone would be so kind as to look this over and make suggestions, I'd appreciate it. Thanks!
Hmm... Looking over this, the code didn't format correctly when I put it in here, so also if someone could explain how to use code tags here... :)