Mundo em Python

Boas Vindas

from tkinter import *
from datetime import datetime
from random import choice root = Tk()
root.geometry("500x500")
root.resizable(0, 0)
root.config(bg="#1e3b3b")
root.title("Boas Vindas")
cores_fundo = [
"#1e3b3b", "#103030", "#e0f7fa", "#00796b", "#004d40",
"#ff5722", "#8bc34a", "#f44336", "#9c27b0", "#3f51b5"
]
def mudar_cor():
cor_fundo = choice(cores_fundo)
root.config(bg=cor_fundo)
titulo.config(bg=cor_fundo, fg="#49e3e3" if cor_fundo != "#f44336" else "black")
texto_sub1.config(bg=cor_fundo, fg="#49e3e3" if cor_fundo != "#f44336" else "black")
def limpar():
Nome_entrada.delete(0, END)
resultado_texto.config(text="")
saudacao_texto.config(text="") def app(event=None):
nome = Nome_entrada.get().strip()
if nome == "":
resultado_texto.config(text="Por favor, insira seu nome!")
return

hora_atual = datetime.now().hour
data_atual = datetime.now().strftime("%d/%m/%Y")
hora_formatada = datetime.now().strftime("%H:%M:%S")
if 6 <= hora_atual < 12:
saudacao = "Bom dia"
elif 12 <= hora_atual < 18:
saudacao = "Boa tarde"
elif 18 <= hora_atual < 24:
saudacao = "Boa noite"
else:
saudacao = "Boa madrugada"
mensagem = f"{saudacao}, {nome}! Seja bem-vindo(a)!\nEspero que você tenha um excelente dia!"
resultado_texto.config(text=mensagem)
saudacao_texto.config(text=f"Data: {data_atual} | Hora atual: {hora_formatada}")
root.after(1000, app)
titulo = Label(text="Boas Vindas", font=("Arial", "35", "bold"), bg="#1e3b3b", fg="#49e3e3")
titulo.place(relx=0.26, rely=0.05)
texto_sub1 = Label(text="Nome:", font=("Arial", "18", "bold"), bg="#1e3b3b", fg="#49e3e3")
texto_sub1.place(relx=0.15, rely=0.2) Nome = StringVar()
Nome_entrada = Entry(textvariable=Nome, font=("Arial", "12", "bold"), bg="white", fg="blue", justify='center')
Nome_entrada.place(relx=0.45, rely=0.2, relwidth=0.45)
but1 = Button(text="Mostrar", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.4, relwidth=0.25, relheight=0.1) but_limpar = Button(text="Limpar", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=limpar)
but_limpar.place(relx=0.4, rely=0.4, relwidth=0.25, relheight=0.1) but_sair = Button(text="Sair", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=root.destroy)
but_sair.place(relx=0.7, rely=0.4, relwidth=0.25, relheight=0.1)
but_mudar_cor = Button(text="Mudar Cor", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'),
command=mudar_cor)
but_mudar_cor.place(relx=0.1, rely=0.55, relwidth=0.25, relheight=0.1) resultado_texto = Label(text="", font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.15)
saudacao_texto = Label(text="", font=("Arial", 10, "bold"), bg="#cfe2f3")
saudacao_texto.place(relx=0.05, rely=0.85, relwidth=0.9, relheight=0.1)
root.bind('<Return>', app) root.mainloop()
0