Tkinter教程值PaneWindow

來源:互聯網
上載者:User
'''Tkinter教程值PaneWindow'''
#PaneWindow(面板)為一gm,用來管理子Widget
'''1.向PanedWindow中添加Pane'''
#使用add方法
# -*- coding: cp936 -*-
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: cp936 -*-
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: cp936 -*-
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方法。

#author:     jcodeer
#blog:    jcodeer.cublog.cn
#email:    jcodeer@126.com

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.