-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
import customtkinter as ctk
from tkinter import messagebox
Dados armazenados
registros = []
Adicionar registro
def adicionar():
descricao = entry_desc.get()
valor = entry_valor.get()
if descricao == "" or valor == "":
messagebox.showerror("Erro", "Preencha todos os campos!")
return
try:
valor = float(valor)
except:
messagebox.showerror("Erro", "O valor deve ser numérico!")
return
registros.append((descricao, valor))
lista.insert(ctk.END, f"{descricao} - R$ {valor:.2f}")
entry_desc.delete(0, ctk.END)
entry_valor.delete(0, ctk.END)
Remover
def remover():
selecao = lista.curselection()
if not selecao:
messagebox.showerror("Erro", "Selecione um item!")
return
indice = selecao[0]
lista.delete(indice)
del registros[indice]
---------------- JANELA -----------------
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("blue")
janela = ctk.CTk()
janela.title("Controle Financeiro - CustomTkinter")
janela.geometry("450x500")
Widgets
ctk.CTkLabel(janela, text="Descrição:").pack(pady=5)
entry_desc = ctk.CTkEntry(janela, width=300)
entry_desc.pack()
ctk.CTkLabel(janela, text="Valor:").pack(pady=5)
entry_valor = ctk.CTkEntry(janela, width=300)
entry_valor.pack()
ctk.CTkButton(janela, text="Adicionar Registro", command=adicionar).pack(pady=10)
ctk.CTkButton(janela, text="Remover Selecionado", fg_color="red", command=remover).pack(pady=10)
lista = ctk.CTkListbox(janela, width=400, height=300)
lista.pack(pady=10)
janela.mainloop()