📜  Python Tkinter PanedWindow

📅  最后修改于: 2020-10-27 02:03:37             🧑  作者: Mango

Tkinter PanedWindow

PanedWindow小部件的作用类似于容器小部件,其中包含一个或多个水平或垂直排列的子小部件(窗格)。用户可以通过使用鼠标移动称为窗框的分隔线来调整子窗格的大小。

每个窗格仅包含一个小部件。 PanedWindow用于在Python应用程序中实现不同的布局。

下面给出了使用PanedWindow的语法。

句法

w= PanedWindow(master, options) 

下面列出了可能的选项。

SN Option Description
1 bg It represents the background color of the widget when it doesn’t have the focus.
2 bd It 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.
3 borderwidth It represents the border width of the widget. The default is 2 pixel.
4 cursor The mouse pointer is changed to the specified cursor type when it is over the window.
5 handlepad This 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.
6 handlesize It represents the size of the handle. The default size is 8 pixels. However, the handle will always be a square.
7 height It 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.
9 relief It represents the type of the border. The default is FLAT.
10 sashpad It represents the padding to be done around each sash. The default is 0.
11 sashrelief It represents the type of the border around each of the sash. The default is FLAT.
12 sashwidth It represents the width of the sash. The default is 2 pixels.
13 showhandle It is set to True to display the handles. The default value is false.
14 Width It 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.

方法

与PanedWindow关联的以下方法。

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

# !/usr/bin/python3
from tkinter import *

def add():
    a = int(e1.get())
    b = int(e2.get())
    leftdata = str(a+b)
    left.insert(1,leftdata)

w1 = PanedWindow()
w1.pack(fill = BOTH, expand = 1)

left = Entry(w1, bd = 5)
w1.add(left)

w2 = PanedWindow(w1, orient = VERTICAL)
w1.add(w2)

e1 = Entry(w2)
e2 = Entry(w2)

w2.add(e1)
w2.add(e2)

bottom = Button(w2, text = "Add", command = add)
w2.add(bottom)

mainloop()

输出: