BPS
BPS

Reputation: 1231

How to properly nest many ttk.PanedWindow one in other?

I want to make UI with 2 bars which may be grabbed with mouse and dragged to adjust widgets sizes.

Why nested ttk.PanedWindow are not displayed? What needs to be done to show labels 1 and 2 on screen in this example?

import tkinter as tk
from tkinter import ttk


root = tk.Tk()
root.bind('<Escape>', lambda e:root.quit())

paned_v = ttk.PanedWindow(root, orient=tk.VERTICAL)
paned_v.add(tk.Label(root, text='1'))
paned_v.add(tk.Label(root, text='2'))
paned_v.pack(fill=tk.BOTH, expand=True)

paned_h = ttk.PanedWindow(root, orient=tk.HORIZONTAL)
paned_h.add(tk.Label(root, text='3'))
paned_h.add(paned_v)
paned_h.pack(fill=tk.BOTH, expand=True)

root.mainloop()

Upvotes: 0

Views: 231

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386352

Panes need to be children of the paned widgets. If you want pane_v to be managed by paned_h then it needs to be a child of paned_h, and you shouldn't call paned_v.pack() since it is being managed by pane_h.

root = tk.Tk()
root.bind('<Escape>', lambda e:root.quit())

paned_h = ttk.PanedWindow(root, orient=tk.HORIZONTAL)
paned_h.pack(fill=tk.BOTH, expand=True)

paned_v = ttk.PanedWindow(paned_h, orient=tk.VERTICAL)
paned_v.add(tk.Label(paned_v, text='1'))
paned_v.add(tk.Label(paned_v, text='2'))

paned_h.add(tk.Label(paned_h, text='3'))
paned_h.add(paned_v)

Strictly speaking, this isn't required. However, this is the simplest way to make sure the stacking order is correct.

Upvotes: 1

Related Questions