from tkinter import *
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Formatar o número de milhares ou milhões")
titulo = Label(text="Formatar o número",
font=("Arial", 28, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.08, rely=0.05)
texto_sub1 = Label(text="Número :",
font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.25)
texto_sub2 = Label(text="Casas decimais:",
font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.38)
Número = StringVar()
Número_entrada = Entry(textvariable=Número,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Número_entrada.place(relx=0.35, rely=0.26, relwidth=0.6)
decimal = StringVar()
decimal_entrada = Entry(textvariable=decimal,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
decimal_entrada.place(relx=0.55, rely=0.39, relwidth=0.4)
def limpar():
Número_entrada.delete(0, END)
decimal_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
n = float(Número.get())
d = int(decimal.get())
mensagem = f"{n:,.{d}f}"
resultado_texto.config(text=mensagem.replace(",", "X").replace(".", ",").replace("X", "."))
except ValueError:
resultado_texto.config(text="Erro de digitação")
but1 = Button(text="Mostrar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.6, 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.6, 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.6, relwidth=0.25, relheight=0.1)
resultado_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
root.mainloop()