Python Tkinter PanedWindow

In this tutorial, we will learn about Python Tkinter PanedWindow. Tkinter PanedWindow is a widget which is used as a container. A PanedWindow can contain one or more child Panes arranged horizontally or vertically.

Here each pane can contain a widget. The movable (via mouse movements)  line to divide between two panes is known as a sash.

Syntax to add Python Tkinter PanedWindow:

w = PanedWindow( master, option)
  • master: This represents the parent window.
  • options: Here is the list of most commonly used options for this widget.

Example Program of Python Tkinter PannedWindow:

from tkinter import *

mainWindow = Tk()

mainWindow.title("PanedWindow Example")
mainWindow.geometry('350x200')

bigPannedWindow = PanedWindow(mainWindow, orient=HORIZONTAL)
bigPannedWindow.pack(fill=BOTH, expand=1)

label = Label(bigPannedWindow, text="This is left pane", bg="red")
bigPannedWindow.add(label)

rightPannedWindow = PanedWindow(bigPannedWindow, orient=VERTICAL)
bigPannedWindow.add(rightPannedWindow)

topPane = Label(rightPannedWindow, text="This is top pane", bg="blue")
rightPannedWindow.add(topPane)

bottomPane = Label(rightPannedWindow, text="This is bottom pane",bg="orange")
rightPannedWindow.add(bottomPane)

mainWindow.mainloop()

Output:

Python Tkinter PanedWindow

This is how it looks when we move(with mouse) sash of PanedWindow.

Python Tkinter PanedWindow

Various possible options in Python Tkinter PanedWindow:

OPTIONDESCRIPTION
bgThis option is used to set the background colour of the widget.
bdThis option is used to set the size of the 3D border around the widget.
borderwidthThis option is used to set the width of the border. By default, it is 2px.
cursorThis option used to set the style of cursor like an arrow, dot etc
handlepadThis option is used to set the distance between the handle and the end of the sash. In the case of horizontal orientation,  it is used to set the distance between the top of the sash and the handle. By default this distance is 8px.
handlesizeThis option is used to set the size of the handle. By default, it is 8px.
heightThis used to set the height of the widget.
orientThis option is used to set the orientation of the PanedWindow.
reliefThis used to set the type of the widget.
sashpadThis option is used to set the padding around each sash.
sashreliefThis option is used to set a border around the sash. By default, it is FLAT.
sashwidthThis option is used to set the width of the sash. By default, it is 2px.
showhandleThis option is used to control the visibility of handle. By default, it is false.
widthThis option is used to set the width of the widget.

Tkinter PanedWindow Methods:

After learning about various available options in Python Tkinter PanedWindow. Its time to check out some available methods for Python Tkinter PanedWindow widget.

METHODSDESCRIPTION
add(child, options)This method is used to add a child widget to the PanedWindow.
get(startindex [,endindex])This method is used to get the text between the specified range.
config(options)This method is used to configure the widget with specified options.
Spread the love