What is PanedWindow widget?
PanedWindow is a container widget or geometry manager widget, which can be used to hold any child widget, arranged in vertically or horizontally. PanedWindow is much similar to split-pane, where each child pane can be resized by the separator lines (sashes) using the pointer/mouse.
Example
The following Python script creates a window containing one PanedWindow with 3 Label widgets. You can resize the label vertically by dragging the separators.
You need to write following code in any text editor and then save it with .py extension. To execute the application, Type py PanedWindowExample.py command in terminal.
from tkinter import * # Top level window window = Tk() window.title("Studyfied.com") window.geometry('350x200') # Create a panedwindow pane = PanedWindow(window, orient=VERTICAL) pane.pack(fill=BOTH, expand=1) # Add some label widgets on panedwindow row1 = Label(pane, text="Row 1", bg="red") pane.add(row1) row2 = Label(pane, text="Row 2", bg="blue") pane.add(row2) row3 = Label(pane, text="Row 3", bg="orange") pane.add(row3) window.mainloop()
Output
The above code produces the following output in windows operating system.
Explanation
Following line creates a Tkinter window
from tkinter import * window = Tk() window.title("Studyfied.com") window.geometry('350x200')
See explanation of Tkinter window – Tkinter top level window
This snippet creates a paned window, the first parameter is the parent widget or window, Here it is “window”, the second parameter is the orientation for child widget by default HORIZONTAL is used. Second line is pane.pack(), it is geometry manager that packs widgets into rows or columns.
# Create a panedwindow pane = PanedWindow(window, orient=VERTICAL) pane.pack(fill=BOTH, expand=1)
The first parameter passed in the pack() method (fill=BOTH) indicates that it fills the entire space of the parent window/widget, vertically and horizontally. The second parameter expand=1 tells that its child widget can expand or take the entire space within it.
This snippet adds three labels with some background color on the paned window. To add widgets on the paned window add() method is used.
# Add some label widgets on panedwindow row1 = Label(pane, text="Row 1", bg="red") pane.add(row1) row2 = Label(pane, text="Row 2", bg="blue") pane.add(row2) row3 = Label(pane, text="Row 3", bg="orange") pane.add(row3)
See how to use label widget – Tkinter label widget
Some panedwindow properties
Property Name | Description |
---|---|
background / bg | Sets the background color of the widget, Default Is platform specific |
borderwidth / bd | The width of the widget’s border. The default is system specific but usually 1 to 2 pixels. |
cursor | The cursor to display when the mouse moves over the widget. By default, the standard cursor is used. |
handlepad | Sets the handle padding/position. Default value is 8. |
handlesize | Sets the handle size. The default value is 8. |
height | Sets the height for the widget. No default value. |
orient | Sets the orientation for child widgets. Default is HORIZONTAL. |
showhandle | Makes the handle visible or invisible. The default value is 0. |
width | Sets the width for the widget. No default value. |
sashwidth | Sets the movable separator (sash) thickness. Default value is 2 |
sashpad | Sets the sash padding. The default value is 2 |