Python Tkinter PanedWindow

Created with Sketch.

Tkinter PanedWindow

The PanedWindow widget acts like a Container widget which contains one or more child widgets (panes) arranged horizontally or vertically. The child panes can be resized by the user, by moving the separator lines known as sashes by using the mouse.

Each pane contains only one widget. The PanedWindow is used to implement the different layouts in the python applications.

The syntax to use the PanedWindow is given below.

Syntax
  1. w= PanedWindow(master, options)

A list of possible options is given below.

SNOptionDescription
1bgIt represents the background color of the widget when it doesn’t have the focus.
2bdIt represents the 3D border size of the widget. The default option specifies that the trough contains no border whereas the arrowheads and slider contain the 2-pixel border size.
3borderwidthIt represents the border width of the widget. The default is 2 pixel.
4cursorThe mouse pointer is changed to the specified cursor type when it is over the window.
5handlepadThis option represents the distance between the handle and the end of the sash. For the horizontal orientation, it is the distance between the top of the sash and the handle. The default is 8 pixels.
6handlesizeIt represents the size of the handle. The default size is 8 pixels. However, the handle will always be a square.
7heightIt represents the height of the widget. If we do not specify the height, it will be calculated by the height of the child window.
8 orient The orient will be set to HORIZONTAL if we want to place the child windows side by side. It can be set to VERTICAL if we want to place the child windows from top to bottom.
9reliefIt represents the type of the border. The default is FLAT.
10sashpadIt represents the padding to be done around each sash. The default is 0.
11sashreliefIt represents the type of the border around each of the sash. The default is FLAT.
12sashwidthIt represents the width of the sash. The default is 2 pixels.
13showhandleIt is set to True to display the handles. The default value is false.
14WidthIt represents the width of the widget. If we don’t specify the width of the widget, it will be calculated by the size of the child widgets.

Methods

There are the following methods that are associated with the PanedWindow.

SNMethodDescription
1add(child, options)It is used to add a window to the parent window.
2get(startindex, endindex)This method is used to get the text present at the specified range.
3config(options)It is used to configure the widget with the specified options.

Example

  1. # !/usr/bin/python3
  2. from tkinter import *
  3. def add():
  4.     a = int(e1.get())
  5.     b = int(e2.get())
  6.     leftdata = str(a+b)
  7.     left.insert(1,leftdata)
  8. w1 = PanedWindow()
  9. w1.pack(fill = BOTH, expand = 1)
  10. left = Entry(w1, bd = 5)
  11. w1.add(left)
  12. w2 = PanedWindow(w1, orient = VERTICAL)
  13. w1.add(w2)
  14. e1 = Entry(w2)
  15. e2 = Entry(w2)
  16. w2.add(e1)
  17. w2.add(e2)
  18. bottom = Button(w2, text = “Add”, command = add)
  19. w2.add(bottom)
  20. mainloop()

Output:

Python Tkinter PanedWindow

 

Leave a Reply

Your email address will not be published. Required fields are marked *