PanedWindow组件是一个空间管理组件,为组件提供了一个框架,允许用户调整应用程序的划分。
import tkinter as tk
window = tk.Tk()
window.title('hello thinter')
height= window.winfo_screenheight()
width= window.winfo_screenwidth()
window.geometry('400x300+%d+%d'%((width-400)/2,(height-300)/2))
m = tk.PanedWindow(orient="vertical")
m.pack(fill="both", expand=1)
top = tk.Label(m, text="top pane")
m.add(top)
bottom = tk.Label(m, text="bottom pane")
m.add(bottom)
window.mainloop()
- 创建三个窗口
import tkinter as tk
window = tk.Tk()
window.title('hello thinter')
height= window.winfo_screenheight()
width= window.winfo_screenwidth()
window.geometry('400x300+%d+%d'%((width-400)/2,(height-300)/2))
m1 = tk.PanedWindow()
m1.pack(fill="both", expand=1)
left = tk.Label(m1, text="left pane")
m1.add(left)
m2 = tk.PanedWindow(orient="vertical")
m1.add(m2)
top = tk.Label(m2, text="top pane")
m2.add(top)
bottom = tk.Label(m2, text="bottom pane")
m2.add(bottom)
window.mainloop()

在窗口上是可以用鼠标进行拖动的,只是线看不到,我们不妨加上手柄看一下
import tkinter as tk
window = tk.Tk()
window.title('hello thinter')
height= window.winfo_screenheight()
width= window.winfo_screenwidth()
window.geometry('400x300+%d+%d'%((width-400)/2,(height-300)/2))
m1 = tk.PanedWindow(showhandle=True,sashrelief="sunken")
m1.pack(fill="both", expand=1)
left = tk.Label(m1, text="left pane")
m1.add(left)
m2 = tk.PanedWindow(orient="vertical",showhandle=True,sashrelief="sunken")
m1.add(m2)
top = tk.Label(m2, text="top pane")
m2.add(top)
bottom = tk.Label(m2, text="bottom pane")
m2.add(bottom)
window.mainloop()

参数
PanedWindow(master=None, **options) (class)
master -- 父组件
**options -- 组件选项,下方表格详细列举了各个选项的具体含义和用法:


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

forget(child)
-- 删除一个子组件
identify(x, y)
-- 给定一个坐标(x, y),返回该坐标所在的元素名称
-- 如果该坐标位于子组件上,返回空字符串
-- 如果该坐标位于分割线上,返回一个二元组(n, 'sash'),n 为 0 表示第一个分割线
-- 如果该坐标位于手柄上,返回一个二元组(n, 'handle'),n 为 0 表示第一个手柄
panecget(child, option)
-- 获得子组件指定选项的值
paneconfig(child, **options)
-- 设置子组件的各种选项
-- 下方表格列举了各个 options 选项具体含义:

paneconfigure(child, **options)
-- 跟 paneconfig() 一样
panes()
-- 将子组件以列表的形式返回
remove(child)
-- 跟 forget() 一样
sash_coord(index)
-- 返回一个二元组表示指定分割线的起点坐标
sash_dragto(index, x, y)
-- 实现将指定的分割线拖拽到一个新的位置
-- 与 sash_mark() 一起实现
sash_mark(index, x, y)
-- 注册当前的鼠标位置
sash_place(index, x, y)
-- 将指定分割线移动到一个新的位置
网友评论