Yo he hecho un programa basico en python 3. Es un convertidor de distancia y lo termine como lo deseo todo excepto el boton de calcular no me funciona. Estaria muy agradecido si me lo podrian resolver. Aqui esta mi codigo y creo que el problema debe estar al final donde defino la funcion y trato de hacer el boton.
Estaria muy agradecido si alguien me podria ayudar.
Código:
from tkinter import *
from tkinter import ttk
root = Tk()
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid()
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
a = StringVar()
b = StringVar()
c = float()
d = float()
e = float()
f = float()
g = ttk.Combobox(mainframe, state='readonly', values=('Km','m','cm','mm','Mi','yd','In'))
g.grid(column=1, row=4)
g.set("Convert From")
h = ttk.Combobox(mainframe, state="readonly", values=('Km','m','cm','mm','Mi','yd','In'))
h.grid(column=2, row=4)
h.set("Convert to")
i=ttk.Entry(mainframe, width=8, textvariable=c)
i.grid(column=3, row=4)
ttk.Label(mainframe, text="This is a simple converter.").grid(column=1, row=1, columnspan=3)
ttk.Label(mainframe, text="You can convert one of these:").grid(column=1, row=2, columnspan=3)
ttk.Label(mainframe, text="Km, m, cm, mm, In, ft, Mi, or yard.").grid(column=1, row=3, columnspan=3)
g.focus_set()
e=1
a=g.get()
b=h.get()
if a == 'Km':
d = 1000.
elif a == 'm':
d = 1.
elif a == 'cm':
d = 0.01
elif a == 'mm':
d = 0.001
elif a == 'In':
d = 0.0254
elif a == 'ft':
d = 0.3048
elif a == 'Mi':
d = 1609.344
elif a == 'yd':
d = 0.9144
else:
pass
if b == 'Km':
e = 1000.
elif b == 'm':
e = 1.
elif b == 'cm':
e = 0.01
elif b == 'mm':
e = 0.001
elif b == 'In':
e = 0.0254
elif b == 'ft':
e = 0.3048
elif b == 'Mi':
e = 1609.344
elif b == 'yd':
e = 0.9144
else:
pass
try:
c=float(c)
except:
pass
def calculate():
c=i.get()
if c != int:
c=0
else:
f = d/e*c
ttk.Label(mainframe, text=f).grid(column=2, row=5, ipady=3)
ttk.Button(mainframe, text="Calculate", command=calculate()).grid(column=3, row=5, ipady=3)
root.mainloop()