TShopping

標題: Python Tkinter 框架控件(Frame) [打印本頁]

作者: woff    時間: 2020-12-25 12:43
標題: Python Tkinter 框架控件(Frame)
Python Tkinter 框架(Frame)控件在屏幕上顯示一個矩形區域,多用來作為容器。
語法
語法格式如下:
  1. w = Frame ( master, option, ... )
複製代碼

序號
可選項& 描述
1
bg
框架背景顏色
2
d
框架的大小,默認為2 個像素
3
光標
鼠標移動到框架時,光標的形狀,可以設置為arrow, circle, cross, plus 等。
4
高度
框架的高度,默認值是0。
5
高亮背景
框架沒有獲得焦點時,高亮邊框的顏色,默認由系統指定。
6
高光色
框架獲得焦點時,高亮邊框的顏色
7
高光厚度
指定高亮邊框的寬度,默認值為0不帶高亮邊框)
8
救濟
邊框樣式,可選的有:FLAT、SUNKEN、RAISED、GROOVE、RIDGE。默認為FLAT。
9
寬度
設置框架寬度,默認值是0。
10
聚焦
指定該組件是否接受輸入焦點(用戶可以通過tab 鍵將焦點轉移上來),默認為false。
實例
  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. # python2  使用 Tkinter
  4. from Tkinter import *
  5. # python3 使用 tkinter
  6. #from tkinter import *
  7. def say_hi():
  8.     print("hello ~ !")

  9. root = Tk()

  10. frame1 = Frame(root)
  11. frame2 = Frame(root)
  12. root.title("tkinter frame")

  13. label= Label(frame1,text="Label",justify=LEFT)
  14. label.pack(side=LEFT)

  15. hi_there = Button(frame2,text="say hi~",command=say_hi)
  16. hi_there.pack()

  17. frame1.pack(padx=1,pady=1)
  18. frame2.pack(padx=10,pady=10)

  19. root.mainloop()
複製代碼



測試輸出結果如下:


文章出處





歡迎光臨 TShopping (http://www.tshopping.com.tw/) Powered by Discuz! X3.2