1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Creating a dynamic window with Tkinter [closed]

Discussão em 'Python' iniciado por Stack, Setembro 11, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to create a simple CRM using Tkinter but I have a problem with creating dynamic buttons and title.

    I want the title and buttons to readjust their size depending on the window size. I tried to make a grid_rowconfigure for each button but it didn't solve it.

    This is my original code for the main page:

    def __init__(self, parent, controller):
    tk.Frame.__init__(self, parent)
    self.controller = controller

    # Configure grid layout for the main page
    self.grid_columnconfigure(0, weight=1)
    self.grid_columnconfigure(1, weight=1)
    self.grid_columnconfigure(2, weight=1)
    self.grid_rowconfigure(0, weight=1)
    self.grid_rowconfigure(1, weight=5)

    # Centered title
    label = tk.Label(self, text="CRM Dashboard", font=("Helvetica", 24))
    label.grid(row=0, column=0, columnspan=3, pady=10, sticky="n")

    # Create three frames for the columns
    customer_frame = tk.Frame(self)
    customer_frame.grid(row=1, column=0, padx=20, pady=20, sticky="nsew")
    customer_frame.grid_rowconfigure(0, weight=1)
    customer_frame.grid_columnconfigure(0, weight=1)

    transactions_frame = tk.Frame(self)
    transactions_frame.grid(row=1, column=1, padx=20, pady=20, sticky="nsew")
    transactions_frame.grid_rowconfigure(0, weight=1)
    transactions_frame.grid_columnconfigure(0, weight=1)

    sales_frame = tk.Frame(self)
    sales_frame.grid(row=1, column=2, padx=20, pady=20, sticky="nsew")
    sales_frame.grid_rowconfigure(0, weight=1)
    sales_frame.grid_columnconfigure(0, weight=1)

    # Buttons under Customer column
    customer_label = tk.Label(customer_frame, text="Customers", font=("Helvetica", 16))
    customer_label.pack(pady=10)

    add_customer_btn = ttk.Button(customer_frame, text="Add Customer", command=lambda: controller.show_frame('CustomerPage'))
    add_customer_btn.pack(fill='x', padx=10, pady=5)

    delete_customer_btn = ttk.Button(customer_frame, text="Delete Customer")
    delete_customer_btn.pack(fill='x', padx=10, pady=5)

    search_customer_btn = ttk.Button(customer_frame, text="Search Customer")
    search_customer_btn.pack(fill='x', padx=10, pady=5)

    # Buttons under Transactions column
    transactions_label = tk.Label(transactions_frame, text="Transactions", font=("Helvetica", 16))
    transactions_label.pack(pady=10)

    add_transaction_btn = ttk.Button(transactions_frame, text="Add Debt", command=lambda: controller.show_frame('TransactionsPage'))
    add_transaction_btn.pack(fill='x', padx=10, pady=5)

    remove_debt_btn = ttk.Button(transactions_frame, text="Remove Debt")
    remove_debt_btn.pack(fill='x', padx=10, pady=5)

    search_debt_btn = ttk.Button(transactions_frame, text="Search Debt")
    search_debt_btn.pack(fill='x', padx=10, pady=5)

    # Buttons under Sales column
    sales_label = tk.Label(sales_frame, text="Sales", font=("Helvetica", 16))
    sales_label.pack(pady=10)

    sales_btn_1 = ttk.Button(sales_frame, text="Add Sales Record", command=lambda: controller.show_frame('SalesPage'))
    sales_btn_1.pack(fill='x', padx=10, pady=5)

    sales_btn_2 = ttk.Button(sales_frame, text="Delete Sales Record")
    sales_btn_2.pack(fill='x', padx=10, pady=5)

    sales_btn_3 = ttk.Button(sales_frame, text="View Sales Summary")
    sales_btn_3.pack(fill='x', padx=10, pady=5)

    Continue reading...

Compartilhe esta Página