Mundo em Python

Aplicação de Tempo do microfone (usando tkinter)

from tkinter import *

root = Tk()
root.geometry("500x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Aplicação de Tempo") titulo = Label(text="Aplicação de Tempo", font=("Arial", "34", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.08, rely=0.05) sub1 = Label(bg="green")
sub1.place(relx=0.3, rely=0.25, relwidth=0.4, relheight=0.4) tempo = Label(text="", bg="#103030", fg='white', font=('verdana', 15, 'bold'))
tempo.place(relx=0.08, rely=0.9) def countdown(tempo_restante):
if tempo_restante > 0:
tempo.config(text="Tempo restante: {} segundos".format(tempo_restante))
sub1.config(bg="green")
if tempo_restante == 15:
sub1.config(bg="yellow")
elif tempo_restante == 5:
tempo.config(text="Tempo restante: {} segundos".format(tempo_restante))
sub1.config(bg="red")
elif tempo_restante == 4:
tempo.config(text="Tempo restante: {} segundos".format(tempo_restante))
sub1.config(bg="yellow")
elif tempo_restante == 3:
tempo.config(text="Tempo restante: {} segundos".format(tempo_restante))
sub1.config(bg="red")
elif tempo_restante == 2:
tempo.config(text="Tempo restante: {} segundos".format(tempo_restante))
sub1.config(bg="yellow")
elif tempo_restante == 1:
tempo.config(text="Tempo restante: {} segundos".format(tempo_restante))
sub1.config(bg="red")
root.after(1000, countdown, tempo_restante - 1)
else:
tempo.config(text="Seu microfone foi desligado.")
start_button.config(state="normal")
sub1.config(bg="red") def start_countdown():
start_button.config(state="disabled") value = resposta1.get()
tempo_inicial = 0
if value == 0:
tempo_inicial = 3 * 60 + 30
elif value == 1:
tempo_inicial = 3 * 60 + 30
elif value == 2:
tempo_inicial = 2 * 60 + 20
elif value == 3:
tempo_inicial = 1 * 60 + 20
elif value == 4:
tempo_inicial = 1 * 60 + 10
elif value == 5:
tempo_inicial = 1 * 60 + 10
elif value == 6:
tempo_inicial = 1 * 60 + 10

countdown(tempo_inicial) resposta1 = IntVar()
Radiobutton(root, text="PS", variable=resposta1, value=0,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.05, rely=0.7)
Radiobutton(root, text="PSD", variable=resposta1, value=1,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.18, rely=0.7)
Radiobutton(root, text="Chega", variable=resposta1, value=2,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.3, rely=0.7)
Radiobutton(root, text="IL", variable=resposta1, value=3,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.45, rely=0.7)
Radiobutton(root, text="BE", variable=resposta1, value=4,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.55, rely=0.7)
Radiobutton(root, text="Livre", variable=resposta1, value=5,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.65, rely=0.7)
Radiobutton(root, text="PAN", variable=resposta1, value=6,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.8, rely=0.7) start_button = Button(root, text="Iniciar", command=start_countdown, font=("Arial", "12"))
start_button.place(relx=0.4, rely=0.8) root.mainloop()
0