close

基本用法如下所示:

import tkinter as tk

root = tk.Tk()

var1 = tk.IntVar() #宣告變數Var1為一個整數值

var2 = tk.IntVar() #宣告變數Var2為一個整數值

chBtn1 = tk.Checkbutton(root, text='read', variable=var1, onvalue=1, offvalue=0) #綁定變數值

chBtn1.pack()

chBtn2 = tk.Checkbutton(root, text='write', variable=var2, onvalue=1, offvalue=0) #綁定變數值

chBtn2.pack()

root.mainloop()

 

基本結構:

chBtn = Checkbutton ( master, option, ... )

tkinter提供Checkbutton共27個參數如下所示:

1. activebackground: 當鼠標點擊時的背景顏色

2. activeforeground: 當鼠標點擊時的前景顏色

3. bg: 背景顏色

4. bitmap: 位元圖

5. bd: 邊框的大小, 默認為2px

6. command: 關聯的function, 當被點擊時執行該function

7. cursor: 光標的形狀設定, 如arrow, circle, cross, plus等

8. disabledforeground: 禁用選項的前景顏色

9. font: 文字字體

10. fg: 選項的前景顏色

11. height: 複選框文字行數, 默認為1

12. highlightcolor: 聚焦的高亮顏色

13. image: 是否使用圖標

14. justify: 顯示多行文字的時候, 設置不同行之間的對齊方式, 有3種模式: LEFT, RIGHT, CENTER

15. offvalue: 設定Checkbutton的值是0或1或者是其他類型的值

16. onvalue: 設定Checkbutton的值是0或1或者是其他類型的值

17. padx: 在x軸方向上的內邊距(padding), 默認為1px

18. pady: 在y軸方向上的內邊距(padding), 默認為1px

19. relief: 邊框樣式, 設置組件3D效果, 有5種模式: FLAT, SUNKEN, RAISED, GROOVE, RIDGE, 默認為FLAT

20. selectcolor: 選中後的顏色, 默認為selectcolor='red'

21. selectimage: 選中後的圖片

22. state: 狀態, 默認為NORMAL

23. text: 顯示的文字內容, 可使用'\n'來對文字進行換行

24. underline: 下滑線, 默認文字都不帶下滑線

25. variable: 變數, 值為1或0, 表示選中或不選中

26. width: 可以設定文字字數, 默認寬度為複選框的文字或圖像所決定的

27. wraplength: 是否設置包裹

Checkbutton提供5個呼叫函式(方法)如下所示:

1. deselect(): Clears (turns off) the checkbutton.

2. flash(): Flashes the checkbutton a few times between its active and normal colors, but leaves it the way it started.

3. invoke(): You can call this method to get the same actions that would occur if the user clicked on the checkbutton to change its state.

4. select(): Sets (turns on) the checkbutton.

5. toggle(): Clears the checkbutton if set, sets it if cleared.

 

 

 

※查詢其他Tkinter GUI元件用法如下※

http://jennaweng0621.pixnet.net/blog/category/6758171

 

arrow
arrow
    文章標籤
    python tkinter checkbutton
    全站熱搜

    楓綺 發表在 痞客邦 留言(0) 人氣()