Mundo em Python

Converter litros para galões Vice-Versa

from tkinter import *
from tkinter import ttk class Indicadores:
def __init__(self, root):
self.root = root
self.janela()
self.frames_da_janela()
self.widgets_frame1()
root.mainloop() def janela(self):
self.root.title("Converter litros para galões Vice-Versa")
self.root.configure(background='#1e3743')
self.root.geometry("300x300")
self.root.resizable(False, False) def frames_da_janela(self):
self.frame_1 = Frame(self.root, bd=4, bg='#dfe3ee', highlightbackground='#759fe6', highlightthickness=2)
self.frame_1.place(relx=0.02, rely=0.02, relwidth=0.96, relheight=0.95) def widgets_frame1(self):
self.abas = ttk.Notebook(self.frame_1)
self.litros_galões = Frame(self.abas)
self.galões_litros = Frame(self.abas)
self.litros_galões.configure(background="#dfe3ee")
self.galões_litros.configure(background="#dfe3ee")
self.abas.add(self.litros_galões, text="Litros para Galões")
self.abas.add(self.galões_litros, text="Galões para Litros ")
self.abas.place(relx=0, rely=0, relwidth=0.98, relheight=0.98) # Litros para Galões
self.Litros = DoubleVar()
self.lb_Litros = Label(self.litros_galões, text="Litros: ", bg='#dfe3ee', fg='#107db2', font=("Arial", "15", "bold"))
self.lb_Litros.place(relx=0.05, rely=0.05)
self.Litros_entry = Entry(self.litros_galões, textvariable=self.Litros, justify='center')
self.Litros_entry.place(relx=0.35, rely=0.05, relwidth=0.45) self.bt_calcular1 = Button(self.litros_galões, text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 14, 'bold'), command=self.butaoclick1)
self.bt_calcular1.place(relx=0.25, rely=0.3, relwidth=0.45, relheight=0.25) self.Galões1 = StringVar()
self.resultado1 = Label(self.litros_galões, textvariable=self.Galões1)
self.resultado1.place(relx=0.05, rely=0.78, relwidth=0.9) # Galões para Litros
self.Galões2 = DoubleVar()
self.lb_Galões2 = Label(self.galões_litros, text="Galões ", bg='#dfe3ee', fg='#107db2', font=("Arial", "15", "bold"))
self.lb_Galões2.place(relx=0.05, rely=0.05)
self.Galões2_entry = Entry(self.galões_litros, textvariable=self.Galões2, justify='center')
self.Galões2_entry.place(relx=0.35, rely=0.05, relwidth=0.45) self.bt_calcular2 = Button(self.galões_litros, text="Calcular", bd=2, bg='#107db2',
fg='white', font=('verdana', 14, 'bold'), command=self.butaoclick2)
self.bt_calcular2.place(relx=0.25, rely=0.3, relwidth=0.45, relheight=0.25) self.Litros3 = StringVar()
self.resultado2 = Label(self.galões_litros, textvariable=self.Litros3)
self.resultado2.place(relx=0.05, rely=0.78, relwidth=0.9) def butaoclick1(self):
l = self.Litros.get()
Galao = l * 0.264172
ra = f"{l} litros são {round(Galao, 2)} galões"
self.Galões1.set(ra) def butaoclick2(self):
g = self.Galões2.get()
litros_resultado = g / 0.264172
rb = f"{g} galões são {round(litros_resultado, 2)} litros"
self.Litros3.set(rb) if __name__ == "__main__":
root = Tk()
Indicadores(root)
0