Como Converter: Horas, Minutos e Segundos (usando tkinter)

apagar.png


 



from tkinter import *
from tkinter import ttk
root =Tk()
class horas():
def __init__(self):
self.root = root
self.janela()
self.converter()
root.mainloop()
def janela(self):
self.root.title("Converter Tempo")
self.root.geometry("370x150")
self.root.resizable(False, False)
def converter (self):
self.abas = ttk.Notebook()
self.horas = Frame(self.abas)
self.minutos = Frame(self.abas)
self.segundos = Frame(self.abas)
self.horas.configure(background="#dfe3ee")
self.minutos.configure(background="#dfe3ee")
self.segundos.configure(background="#dfe3ee")

self.abas.add(self.horas, text="Converter as horas")
self.abas.add(self.minutos, text="Converter os minutos")
self.abas.add(self.segundos, text="Converter os segundos")
self.abas.place(relx=0, rely=0, relwidth=0.98, relheight=0.98)
# Horas a Converter
self.numero_hora = DoubleVar()
self.lb_numero_hora = Label(self.horas, text="Horas", bg='#dfe3ee', fg='#107db2')
self.lb_numero_hora.place(relx=0.05, rely=0.1)
self.numero_hora_entry = Entry(self.horas, textvariable=self.numero_hora)
self.numero_hora_entry.place(relx=0.4, rely=0.1, relwidth=0.1)
# Minutos a Coverter
self.horas_para_minutos = StringVar()
self.lb_horas_para_minutos = Label(self.horas, text="Minutos ", bg='#dfe3ee', fg='#107db2')
self.lb_horas_para_minutos.place(relx=0.05, rely=0.35)
self.horas_para_minutos_resultado = Label(self.horas, textvariable=self.horas_para_minutos)
self.horas_para_minutos_resultado.place(relx=0.4, rely=0.35, relwidth=0.2)

# Segundos a Coverter
self.horas_para_segundos = StringVar()
self.lb_horas_para_segundos = Label(self.horas, text="Segundos ", bg='#dfe3ee', fg='#107db2')
self.lb_horas_para_segundos.place(relx=0.05, rely=0.55)
self.horas_para_minutos_resultado = Label(self.horas, textvariable=self.horas_para_segundos)
self.horas_para_minutos_resultado.place(relx=0.4, rely=0.55, relwidth=0.2)

# Butão
self.bt_calcular1 = Button(self.horas, text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 8, 'bold'), command=self.butao1)
self.bt_calcular1.place(relx=0.7, rely=0.25, relwidth=0.25, relheight=0.35)

# Converter Minutos para Horas e Segundos
self.conminutos = DoubleVar()
self.lb_conminutos = Label(self.minutos, text="Minutos ", bg='#dfe3ee', fg='#107db2')
self.lb_conminutos.place(relx=0.05, rely=0.1)
self.conminutos_entry = Entry(self.minutos, textvariable=self.conminutos)
self.conminutos_entry.place(relx=0.4, rely=0.1, relwidth=0.1)
# Minutos a Coverter
self.minutos_para_horas = StringVar()
self.lb_minutos_para_horas = Label(self.minutos, text="Horas ", bg='#dfe3ee', fg='#107db2')
self.lb_minutos_para_horas.place(relx=0.05, rely=0.35)
self.minutos_para_horas_resultado = Label(self.minutos, textvariable=self.minutos_para_horas)
self.minutos_para_horas_resultado.place(relx=0.4, rely=0.35, relwidth=0.2)

# Segundos a Coverter
self.minutos_para_segundos = StringVar()
self.lb_minutos_para_segundos = Label(self.minutos, text="Segundos ", bg='#dfe3ee', fg='#107db2')
self.lb_minutos_para_segundos.place(relx=0.05, rely=0.55)
self.minutos_para_segundos_resultado = Label(self.minutos, textvariable=self.minutos_para_segundos)
self.minutos_para_segundos_resultado.place(relx=0.4, rely=0.55, relwidth=0.2)

# Butão
self.bt_calcular2 = Button(self.minutos, text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 8, 'bold'), command=self.butao2)
self.bt_calcular2.place(relx=0.7, rely=0.25, relwidth=0.25, relheight=0.35)

# Converter Segundos para Horas e Minutos
self.consegundos = IntVar()
self.lb_consegundos = Label(self.segundos, text="Segundos ", bg='#dfe3ee', fg='#107db2')
self.lb_consegundos.place(relx=0.05, rely=0.1)
self.consegundos_entry = Entry(self.segundos, textvariable=self.consegundos)
self.consegundos_entry.place(relx=0.4, rely=0.1, relwidth=0.15)
# Horas a Coverter
self.segundos_para_horas = StringVar()
self.lb_segundos_para_horass = Label(self.segundos, text="Horas ", bg='#dfe3ee', fg='#107db2')
self.lb_segundos_para_horass.place(relx=0.05, rely=0.35)
self.segundos_para_horas_resultado = Label(self.segundos, textvariable=self.segundos_para_horas)
self.segundos_para_horas_resultado.place(relx=0.4, rely=0.35, relwidth=0.2)

# Minutos a Coverter
self.segundos_para_minutos = StringVar()
self.lb_segundos_para_minutos = Label(self.segundos, text="Segundos ", bg='#dfe3ee', fg='#107db2')
self.lb_segundos_para_minutos.place(relx=0.05, rely=0.55)
self.segundos_para_minutos_resultado = Label(self.segundos, textvariable=self.segundos_para_minutos)
self.segundos_para_minutos_resultado.place(relx=0.4, rely=0.55, relwidth=0.2)

# Butão
self.bt_calcular3 = Button(self.segundos, text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 8, 'bold'), command=self.butao3)
self.bt_calcular3.place(relx=0.7, rely=0.25, relwidth=0.25, relheight=0.35)

def butao1(self):
h = self.numero_hora.get()
hminutos = h*60
hsegundos =h*3600
return self.horas_para_minutos.set(hminutos),self.horas_para_segundos.set(hsegundos)

def butao2(self):
m = self.conminutos.get()
minuparahoras =round((m / 60),2)
minuparasegundos = m * 60
return self.minutos_para_horas.set(minuparahoras),self.minutos_para_segundos.set(minuparasegundos)

def butao3(self):
s = self.consegundos.get()
segunparahoras = round((s/3600), 5)
seguparaminutos = round((s/60), 5)
return self.segundos_para_horas.set(segunparahoras), self.segundos_para_minutos.set(seguparaminutos)
horas()

Comentários

Mensagens populares deste blogue

Criar Cartões de Visita

12 signos egípcios

Calcular a percentagem de ocupação