When I "forget" or "add" a widget to a PanedWindow widget before any resize of the root window, then the root window size is changed by this actions. But after resizing the root window by the mouse pointer, "forget" or "add" do not change the size of the window anymore, but only the "subwindows" of the PanedWindow change their sizes.
How can I keep the root window size stable during these actions even before any root window resize?
This is my example code:
import tkinter as tk
from tkinter import ttk
state = "shown"
def hide_show(paned, canvas):
global state
if state=="shown":
paned.forget(canvas)
state = "hidden"
else:
paned_window.add(canvas, weight= 1)
state = "shown"
root = tk.Tk()
paned_window = ttk.PanedWindow(root, orient=tk.HORIZONTAL,)
button = ttk.Button (root, text="hide/show", command=lambda: hide_show(paned_window, canvas2))
paned_window.grid(row=0, sticky=(tk.W, tk.E, tk.S, tk.N))
button.grid (row=1, sticky=tk.W)
root.rowconfigure (0, weight=1)
root.rowconfigure (1, weight=0)
root.columnconfigure(0, weight=1)
canvas1 = tk.Canvas(paned_window, height=100, width=100, bg="red")
canvas1.grid()
paned_window.add(canvas1, weight= 1)
canvas2 = tk.Canvas(paned_window, height=100, width=100, bg="green")
canvas2.grid()
paned_window.add(canvas2, weight= 1)
root.mainloop()
>Solution :
I think setting root.geometry() to a fixed value will help, as it will create a window of fixed dimensions preventing unwanted resizing.