Tkinter教程之Frame篇

來源:互聯網
上載者:User
'''Tkinter教程之Frame篇'''
#Frame就是螢幕上的一塊矩形地區,多是用來作為容器(container)來布局表單。
'''1.建立Frame'''
# -*- coding: cp936 -*-
from Tkinter import *
root = Tk()
#以不同的顏色區別各個frame
for fm in ['red','blue','yellow','green','white','black']:
    #注意這個建立Frame的方法與其它建立控制項的方法不同,第一個參數不是root
    Frame(height = 20,width = 400,bg = fm).pack()
root.mainloop()
#添加不同顏色的Frame,大小均為20*400
'''2.向Frame中添加Widget'''
# -*- coding: cp936 -*-
from Tkinter import *
root = Tk()
fm = []
#以不同的顏色區別各個frame
for color in ['red','blue']:
    #注意這個建立Frame的方法與其它建立控制項的方法不同,第一個參數不是root
    fm.append(Frame(height = 200,width = 400,bg = color))
#向下面的Frame中添加一個Label
Label(fm[1],text = 'Hello label').pack()
fm[0].pack()
fm[1].pack()
root.mainloop()
#Label被添加到下面的Frame中了,而不是root預設的最上方。
#大部分的方法來自gm,留到後面gm時再介紹
'''3.Tk8.4以後Frame又添加了一類LabelFrame,添加了Title的支援'''
from Tkinter import *
root = Tk()
for lf in ['red','blue','yellow']:
    #可以使用text屬性指定Frame的title
    LabelFrame(height = 200,width = 300,text = lf).pack()
root.mainloop()

#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.