Celsius to Fahrenheit Converter GUI program python

The main problem is the lack of main().

You should add main() to the very end of your code. That said you really don’t need the main() function to begin with.

You are trying to assign a string as a text-variable in the entry field and this wont do anything. If you wish to use the textvariable argument then you need to use something like StringVar() or IntVar(). We don’t need anything like that here. We can simple use the entry.get() method within your convert function.

By moving this get() method to the convert function we can remove the lambda from your button command. Simply do command=convert.

With those changes you can have something simple like the below.

from tkinter import *


def convert():
    x = entry.get()
    if x != "":    
        cel=int(x)
        far=(9/5*(cel))+32
        print(far)

root=Tk()
root.title("Some GUI")
root.geometry("400x700")

Button(root, text="Total", command=convert).pack()
entry = Entry(root)
entry.pack()
Label(root,text="Enter a Celcius temperature.").pack()

root.mainloop()

Leave a Comment