Python --- (eighteen) Tkinter widgets: PanedWindow

Previous: Python - (seventeen) Tkinter widgets: Spinbox


                                          The Tkinter PanedWindow Widget

## Introduction

PanedWindow components (Tk8.4 new) is a space management component. With Frame components similar, it is to provide a framework for the assembly, but let PanedWindow allow the user to adjust the application of space division.

When to use PanedWindow ## components?

When you need to provide a framework for multi-space available to the user to adjust the time, you can use PanedWindow components. PanedWindow appliance generates a pane independently for each sub-assembly, the user can freely adjust the size of the pane.

##usage

Create a 2 pane PanedWindow component is very simple:

from tkinter import *

m = PanedWindow(orient=VERTICAL)
m.pack(fill=BOTH,expand=1)

top = Label(m,text="top pane")
m.add(top)
bottom = Label(m,text="bottom pane")
m.add(bottom)

mainloop()

Here Insert Picture Description                        Here Insert Picture Description
Here Insert Picture Description
   (Analysis: Simple framework, for example, is divided into said two panes, the upper and lower, or left and right, above PanedWindow when instantiating the object, is provided to orient VERTICAL, because he is about delimited by default, get here a vertical vERTICAL, that he was brought to the attention of the distribution, and then when the pack is provided so that the frame covers BOTH global option, then again the Label two, add a method to display respectively above and below

   1 just started running to get shots, and use Frame found no difference ah, his discovery after pulling them apart, and then when you put the mouse on "top pane" below a Diudiu, you will find the mouse to change the style, found that by dragging the left mouse button you can change their layout, such as third shots, so you can guess, "top pane" below a Diudiu is a dividing line, but do not see)

Creating a 3-pane PanedWindow components you need some tips:

from tkinter import *

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

left = Label(m1,text="left pane")
m1.add(left)

m2 = PanedWindow(orient=VERTICAL)
m1.add(m2)

top = Label(m2,text="top pane")
m2.add(top)

bottom = Label(m2,text="bottom pane")
m2.add(bottom)

mainloop()

Here Insert Picture Description
Here Insert Picture Description
   (Analysis: First, first take a small pane, the default is around, left = Label (m1, text = "left pane") created after a good left, and then instantiate a PaneWindow the right, set the orient and options for VERTICAL vertical, and then to note is m1.add (m2), after the example of the good is to add to the m1, m1 is on the right, and so is left is a Label, the right is a PaneWindow, and then based on this PaneWindow create two Label

   After running can still move their position, that they have a hidden line, we can not see, but can use the mouse to slowly get to feel him)

We just set "showhandle" option and the "ashrelief" option when instantiated PanedWindow can see them

from tkinter import *


m1 = PanedWindow(showhandle = True,sashrelief=SUNKEN)
m1.pack(fill=BOTH,expand=1)

left = Label(m1,text="left pane")
m1.add(left)

m2 = PanedWindow(orient=VERTICAL,showhandle = True,sashrelief=SUNKEN)
m1.add(m2)

top = Label(m2,text="top pane")
m2.add(top)

bottom = Label(m2,text="bottom pane")
m2.add(bottom)

mainloop()            

Here Insert Picture Description
Here Insert Picture Description
   (Analysis: is when instantiating PanedWindow the showhandle option is set to True, ashrelief option is the dividing line, it's style is set to "sunken" is to the concave.
   That little square, we'll call it handle as long as you put the mouse on the dividing line, you can adjust its position, then you can set the position of the handle that is by setting small square handlesize, he default is 8 pixels so close to the edges of the position)

##parameter

PanedWindow(master=None, **options) (class)

master - parent component

** options - component options, the table below details the specific meaning and usage of each option:

Options meaning
background Set the background color
bg Like background
borderwidth Set the border width
bd Like borderwidth
cursor 1. Specify when the mouse on the mouse PanedWindow drifting pattern
2. The default value is specified by the system
handlepad 1. 调节“手柄”的位置
2. 例如 orient="vertical",则 handlepad 选项表示“分割线”上的手柄与左端的距离
3. 默认值是 8 像素
handlesize 1. 设置“手柄”的尺寸(由于“手柄”必须是一个正方形,所以是设置正方形的边长)
2. 默认值是 8 像素
height 1. 设置 PanedWindow 的高度
2. 如果忽略该选项,则高度由子组件的尺寸决定
opaqueresize 1. 该选项定义了用户调整窗格尺寸的操作
2. 如果该选项的值为 True(默认),窗格的尺寸随用户鼠标的拖拽而改变
3. 如果该选项的值为 False,窗格的尺寸在用户释放鼠标的时候才更新到新的位置
orient 1. 指定窗格的分布方式
2. 可以是 "horizontal"(横向分布)和 "vertical"(纵向分布)
relief 1. 指定边框样式
2. 默认值是 "flat"
3. 另外你还可以设置 "sunken","raised","groove" 或 "ridge"
sashpad 设置每一条分割线到窗格间的间距
sashrelief 1. 设置分割线的样式
2. 默认值是:"flat"
3. 另外你还可以设置 "sunken","raised","groove" 或 "ridge"
sashwidth 设置分割线的宽度
showhandle 1. 设置是否显示调节窗格的手柄
2. 默认值为 False
width 1. 设置 PanedWindow 的宽度
2. 如果忽略该选项,则高度由子组件的尺寸决定

##方法

add(child, **options)
– 添加一个新的子组件到窗格中
– 下方表格列举了各个 options 选项具体含义:

选项 含义
after 添加新的子组件到指定子组件后边
before 添加新的子组件到指定子组件前边
height 指定子组件的高度
minsize 1. 该选项控制窗格不得低于的值
2. 如果 orient="horizontal",表示窗格的宽度不得低于该选项的值
3. 如果 orient="vertical",表示窗格的高度不得低于该选项的值
padx 指定子组件的水平间距
pady 指定子组件的垂直间距
sticky 1. 当窗格的尺寸大于子组件时,该选项指定子组件位于窗格的位置
2. 可选的值有:"e"、"s"、"w"、"n"(分别代表东南西北四个方位)以及它们的组合值
3. 例如 NE 表示子组件显示在右上角的位置
width 指定子组件的宽度

forget(child)
– 删除一个子组件

identify(x, y)
– 给定一个坐标(x, y),返回该坐标所在的元素名称
– 如果该坐标位于子组件上,返回空字符串
– 如果该坐标位于分割线上,返回一个二元组(n, ‘sash’),n 为 0 表示第一个分割线
– 如果该坐标位于手柄上,返回一个二元组(n, ‘handle’),n 为 0 表示第一个手柄

panecget(child, option)
– 获得子组件指定选项的值

paneconfig(child, **options)
– 设置子组件的各种选项
– 下方表格列举了各个 options 选项具体含义:

选项 含义
after 添加新的子组件到指定子组件后边
before 添加新的子组件到指定子组件前边
height 指定子组件的高度
minsize 1. 该选项控制窗格不得低于的值
2. 如果 orient="horizontal",表示窗格的宽度不得低于该选项的值
3. 如果 orient="vertical",表示窗格的高度不得低于该选项的值
padx 指定子组件的水平间距
pady 指定子组件的垂直间距
sticky 1. 当窗格的尺寸大于子组件时,该选项指定子组件位于窗格的位置
2. 可选的值有:"e"、"s"、"w"、"n"(分别代表东南西北四个方位)以及它们的组合值
3. 例如 NE 表示子组件显示在右上角的位置
width Specifies the width of the subassembly

paneconfigure (Child, ** Options)
- with paneconfig () as

Panes ()
- returns a sub-assembly in the form of a list

the Remove (Child)
- now forget () as

sash_coord (index)
- Returns a specified starting coordinate tuple represents a division line

sash_dragto (index, X, Y)
- to achieve the specified division lines dragging to a new location
implemented with sash_mark () -

sash_mark (index, the X-, the y-)
- registered current mouse position

sash_place (index, X, Y)
- the specified division lines move to a new location


Next:

Published 247 original articles · won praise 116 · views 280 000 +

Guess you like

Origin blog.csdn.net/w15977858408/article/details/104216937