Jason (toomanywhispers) wrote in littlescripts,
Jason
toomanywhispers
littlescripts

Hello! Sorry it's been a while since the last update, I've been looking for work. Here's the latest version of the converter, with Celc.->Fare. converting, Fare.->Celc. converting, and the Tkinter GUI implemented.



# Converter 0.1.0
# Created by Jason Capron
# Licenced under the GPL (Check your Python folder, including it here would be like appending a dictionary to a post-it note)
.
from Tkinter import *
win=Tk()
b1 = Button(win,text="Convert to Farenheit")
b2 = Button(win,text="Convert to Celcius")
v = IntVar()
w = Text(win, height=1, width=20)
e = Entry(win,textvariable=v)
e.pack()
w.pack()
.
def but1():
....a = ((v.get()*9)/5)+32
....w.delete(1.0,END)
....print w.insert(INSERT,a)
.
def but2():
....b = ((v.get()-32)*5)/9
....w.delete(1.0,END)
....print w.insert(INSERT,b)
.
.
b1.configure(command=but1)
b2.configure(command=but2)
e.pack()
b1.pack()
b2.pack()
w.pack()
win.mainloop()



As usual, the periods represent spacing.

A look at the code:

"
def but1():
....a = ((v.get()*9)/5)+32
....w.delete(1.0,END)
....print w.insert(INSERT,a)
"

Is the conversion function,
"b1.configure(command=but1)" makes the gui button for converting to celsius activate the function.
"a = ((v.get()*9)/5)+32" Makes the variable "a" equal the entry in the entry box
"e = Entry(win,textvariable=v)" converted to celcius. (Multiplying it by nine, then dividing it by 5, then adding 32.)

"w.delete(1.0,END)" Clears the text box before "print w.insert(INSERT,a)" prints the converted temperature "a" to the text box. This is so the program can be used multiple times without having to restart it each time.


Todo:
Arrange the GUI components so they're not just thrown into the frame.
Make the buttons equal length.
Shrink the entry and text boxes.
Make the gui more presentable.



Edit: Fixed the lj-cut. Fixed some spelling errors.
  • Post a new comment

    Error

    default userpic
  • 0 comments