def store_temp(sel_temp):
global tempVal
tempVal = sel_temp
def call_convert(rlabel1, inputn, number2Input, numberInput):
tem = inputn.get()
densidade = number2Input.get()
try:
tem = float(tem)
densidade = float(densidade)
except ValueError:
rlabel1.config(text="Por favor, insira valores válidos.")
return
if tempVal == 'Litros':
gramas = tem * densidade
rlabel1.config(text=f"{tem} Litros é igual a {gramas:.2f} Gramas")
elif tempVal == 'Gramas':
litros = tem / densidade
rlabel1.config(text=f"{tem} Gramas é igual a {litros:.2f} Litros")
root = tk.Tk()
root.geometry('400x300')
root.title('Litros para Gramas e Vice-Versa')
root.configure(background='#09A3BA')
root.resizable(width=False, height=False)
root.grid_columnconfigure(1, weight=1)
root.grid_rowconfigure(0, weight=1)
numberInput = tk.DoubleVar()
number2Input = tk.DoubleVar()
var = tk.StringVar()
titulo = tk.Label(root, text="Litros para Gramas e Vice-Versa", background='#09A3BA', foreground="#FFFFFF",
font=("Arial", "18", "bold"))
titulo.place(relx=0.05, rely=0.05)
input_label = tk.Label(root, text="Quantidade:", background='#09A3BA', foreground="#FFFFFF",
font=("Arial", "15", "bold"))
input_entry = tk.Entry(root, textvariable=numberInput, justify='center')
densidade_label = tk.Label(root, text="Densidade (g/mL):", background='#09A3BA', foreground="#FFFFFF",
font=("Arial", "15", "bold"))
densidade_entry = tk.Entry(root, textvariable=number2Input, justify='center')
input_label.place(relx=0.2, rely=0.25)
input_entry.place(relx=0.6, rely=0.25)
densidade_label.place(relx=0.1, rely=0.45)
densidade_entry.place(relx=0.6, rely=0.45)
result_label1 = tk.Label(root, background='#09A3BA', foreground="#FFFFFF",font=("Arial","13","bold"))
result_label1.place(relx=0.05, rely=0.9)
dropDownList = ["Litros", "Gramas"]
dropdown = tk.OptionMenu(root, var, *dropDownList, command=store_temp)
var.set(dropDownList[0])
dropdown.place(relx=0.7, rely=0.55)
dropdown.config(background='#09A3BA', foreground="#FFFFFF")
dropdown["menu"].config(background='#09A3BA', foreground="#FFFFFF")
call_convert_partial = partial(call_convert, result_label1, input_entry, number2Input, numberInput)
result_button = tk.Button(root, text="Convert", command=call_convert_partial, background='#09A3BA',
foreground="#FFFFFF",
font=("Arial", "15", "bold"))
result_button.place(relx=0.25, rely=0.7, relwidth=0.45)
root.mainloop()
Comentários
Enviar um comentário