'''Tkinter教程篇PaneWindow'''
# PaneWindow(面板)为一gm,用来管理子Widget
'''1.向PanedWindow中添加Pane'''
# 使用add方法
# -*- coding: utf-8 -*-
from tkinter import *
root = Tk()
panes = PanedWindow(orient=VERTICAL)
panes.pack(fill=BOTH, expand=1)
for w in [Label, Button, Checkbutton, Radiobutton]:
panes.add(w(panes, text='hello'))
root.mainloop()
# 每个pane中创建一个widget
'''2.删除PanedWindow指定的pane'''
# 使用forget/remove方法
# -*- coding: utf-8 -*-
from tkinter import *
root = Tk()
ws = []
panes = PanedWindow(orient=VERTICAL)
panes.pack(fill=BOTH, expand=1)
# 创建四个pane
for w in [Label, Button, Checkbutton, Radiobutton]:
ws.append(w(panes, text='hello'))
for w in ws:
panes.add(w)
# 从panes中删除包含子Button的pane,使用remove与forget相同
panes.forget(ws[1])
# panes.remove(ws[1])
root.mainloop()
# 只有三个widget,Button已被删除。
'''3.在PanedWindow指定位置添加一个pane'''
# 使用paneconfig方法
# -*- coding: utf-8 -*-
from tkinter import *
root = Tk()
ws = []
ps = PanedWindow(orient=VERTICAL)
ps.pack(fill=BOTH, expand=1)
# 创建四个pane
for w in [Label, Button, Checkbutton, Radiobutton]:
ws.append(w(ps, text='hello'))
for w in ws:
ps.add(w)
# 在0之后添加一个Lable,出错!!!
# ps.after(ws[0],Label(ps,text = 'world'))
# 注意被添加的widget是第一个参数,after指定是位于那一个widget之后
# 不要与after方法混淆了
ps.paneconfig(Label(ps, text='world'), after=ws[0])
root.mainloop()
# 这个widget主要也是用来做Container的,使用了大量的gm方法。