Home > database >  Unable to display buttons on the right hand side of the tkinter GUI
Unable to display buttons on the right hand side of the tkinter GUI

Time:01-05

I'm trying to create a 800x800 GUI where on left hand side I need a treeview to later display data from MySQL, and on right hand side, I am struggling to display five buttons "Read Excel", "Invoice Per Order", "Save PDF", and "Close". Treeview is showing but no one button is visible at the moment. What should I do?

Here is my code:

import tkinter as tk
from tkinter import ttk

# Create the root window
root = tk.Tk()
root.geometry("800x800")

# Create the treeview
treeview = ttk.Treeview(root)
treeview.pack(side="left", fill="both", expand=True)

# Create the buttons
read_excel_button = tk.Button(root, text="Read Excel")
invoice_per_order_button = tk.Button(root, text="Invoice per Order")
save_pdf_button = tk.Button(root, text="Save PDF")
close_button = tk.Button(root, text="Close")

# Place the buttons in a frame and pack the frame to the right of the root window
button_frame = tk.Frame(root)
button_frame.pack(side="right", fill="both")
read_excel_button.pack(side="top", in_=button_frame)
invoice_per_order_button.pack(side="top", in_=button_frame)
save_pdf_button.pack(side="top", in_=button_frame)
close_button.pack(side="top", in_=button_frame)

# Run the Tkinter event loop
root.mainloop()

CodePudding user response:

it works by removing parameters from .pack() methods on each button.

button_frame = tk.Frame(root)
button_frame.pack(side="right", fill="both")
read_excel_button.pack()
invoice_per_order_button.pack()
save_pdf_button.pack()
close_button.pack()

CodePudding user response:

You are using duplicated between line 18-25. You don't needed frame for pack()

Easier for you:

import tkinter as tk
from tkinter import ttk


# Create the root window
root = tk.Tk()
root.geometry("800x800")

# Create the treeview
treeview = ttk.Treeview(root)
treeview.pack(side="left", fill="both", expand=True)

# Create the buttons
read_excel_button = tk.Button(root, text="Read Excel").pack()
invoice_per_order_button = tk.Button(root, text="Invoice per Order").pack()
save_pdf_button = tk.Button(root, text="Save PDF").pack()
close_button = tk.Button(root, text="Close").pack()


# Run the Tkinter event loop
root.mainloop()

Output:

enter image description here

  • Related