I made a Tkinter app using Python. I want it to auto-resize and fill the whole window no matter how I resize it. The problem is that when I expand the window size (using my cursor), grey space appears on the borders to fill the gaps (see the image below).
Here is the code minus the unnecessary details :
import tkinter as tk
from tkinter import ttk
import openpyxl
root = tk.Tk()
frame = ttk.Frame(root)
frame.pack()
widgets_frame = ttk.LabelFrame(frame, text = "Insert Data")
widgets_frame.grid(row = 0, column = 0, padx = 20, pady = 10)
day_label = ttk.Label(widgets_frame, text = "Date")
day_label.grid(row = 1, column = 0, padx = 5, pady = (0, 5), sticky = "ew")
day_entry = ttk.Entry(widgets_frame)
day_entry.grid(row = 2, column = 0, padx = 5, pady = (0, 5), sticky = "ew")
walking_entry = ttk.Entry(widgets_frame)
walking_entry.insert(0, "Walking duration (min)")
walking_entry.bind("<FocusIn>", lambda e: walking_entry.delete('0', 'end'))
walking_entry.grid(row = 3, column = 0, padx = 5, pady = (0, 5), sticky = "ew")
button = ttk.Button(widgets_frame, text = "Insert")
button.grid(row = 4, column = 0, padx = 5, pady = 5, sticky = "nsew")
treeFrame = ttk.Frame(frame)
treeFrame.grid(row = 0, column = 1, pady = 10)
treeScroll = ttk.Scrollbar(treeFrame)
treeScroll.pack(side = "right", fill = "y")
cols = ("Day", "Walking")
treeview = ttk.Treeview(treeFrame, show = "headings", yscrollcommand = treeScroll.set, columns = cols, height = 13)
treeview.column("Day", width = 100)
treeview.column("Walking", width = 50)
treeview.pack()
treeScroll.config(command = treeview.yview)
root.mainloop()
Does anybody have a suggestion that would help me solve this issue ? Thanks.
I added this line of code because, in another thread, they said it helps with expanding the widgets equally when the window size increases :
root.grid_columnconfigure(0,weight = 1)
root.grid_columnconfigure(1,weight = 1)
root.grid_rowconfigure(0, weight = 1)
root.grid_rowconfigure(1, weight = 1)
root.grid_rowconfigure(2, weight = 1)
root.grid_rowconfigure(3, weight = 1)
root.grid_rowconfigure(4, weight = 1)
Unfortunately, even after doing so, I didn't notice any changes.
You could use expand = True, fill = BOTH
as an attribute for the required widgets to expand them to full size.