PANEDWINDOW IN TKINTER
In this tutorial, we are going to learn about the PanedWindow in tkinter and discuss their sub-panedwindows. Also, learn about its features and methods followed by a handy example.
What is PanedWindow in Tkinter?
The Panedwindow in tkinter is a container that holds together one or more than sub-panedwindow which contains their own sub-panedwindows and so on. We can always resize these panes upon our choice by using a mouse. Each pane holds one widget. We can implement the panes horizontally and vertically. The syntax for panedwindow is:
Panedwindow_tk = PanedWindow ( window, features )
Panedwindow features and properties are:
1 | bg | Declares the background color of the widget. |
2 | bd | Displays the 3D border size. |
3 | borderwidth | Specifies the represents border width of the widget. Default width is 2px. |
4 | cursor | Shows the type of cursor when the mouse is hovered over the PanedWindow. The default is a pointed arrow cursor. |
5 | handlepad | 8 is the default size. |
6 | handlesize | 8 is the default size. |
7 | height | It decides the height of the panedwindow. |
8 | orient | The orientation by default is set to HORIZONTAL. |
9 | relief | This displays different types of borders like SUNKEN, RAISED, GROOVE, and RIDGE. |
10 | sashpad | It specifies the padding around each sash. Default value is 0. |
11 | sashrelief | This displays different types of sash borders. |
12 | sashwidth | It specifies the width of the sash. Default is 2px. |
13 | showhandle | This method is set to True for displaying handles. Default value is FALSE. |
14 | Width | This feature sets the width of the panedwindow. |
Methods for a panedwindow widgets are:
1 | add(child, options) | This method is used to add panedwindows within the specified range. |
2 | get(startindex, endindex) | It fetches the absolute index of the specified index |
3 | config(options) | It configures with widget within the specified options. |
Creating Panedwindow in Tkinter
You can create simple a panedwindow widget as follows:
from tkinter import * screen = PanedWindow() screen.pack(fill=BOTH, expand=1) left = Label(screen, text="left pane") screen.add(left) m2 = PanedWindow(screen, orient=VERTICAL) screen.add(m2) top = Label(m2, text="top pane") m2.add(top) bottom = Label(m2, text="bottom pane") m2.add(bottom) mainloop()
Output will be:
References have been used from here