close

基本用法如下:

import tkinter as tk

root = tk.Tk()

scrollbar = tk.Scrollbar(root).pack()

root.mainloop()

搭配Listbox組件方法:

import tkinter as tk

root = tk.Tk()

scrollbar = tk.Scrollbar(root)

scrollbar.pack(side=tk.RIGHT, fill=tk.Y)

listbox = tk.Listbox(root, yscrollcommand = scrollbar.set)

for i in range(100):

    listbox.insert(i, str(i))

listbox.pack(side=tk.LEFT, fill=tk.BOTH)

scrollbar.config(command=listbox.yview)

root.mainloop()

 

基本結構:

scrollbar = Scrollbar ( master, option, ... )

tkinter提供Scrollbar共16個參數如下所示:

1. activebackground: The color of the slider and arrowheads when the mouse is over them.

2. bg: The color of the slider and arrowheads when the mouse is not over them.

3. bd: The width of the 3-d borders around the entire perimeter of the trough, and also the width of the 3-d effects on the arrowheads and slider. Default is no border around the trough, and a 2-pixel border around the arrowheads and slider.    

4. command: A procedure to be called whenever the scrollbar is moved.

5. cursor: The cursor that appears when the mouse is over the scrollbar.

6. elementborderwidth: The width of the borders around the arrowheads and slider. The default is elementborderwidth=-1, which means to use the value of the borderwidth option.

7. highlightbackground: The color of the focus highlight when the scrollbar does not have focus.

8. highlightcolor: The color of the focus highlight when the scrollbar has the focus.

9. highlightthickness: The thickness of the focus highlight. Default is 1. Set to 0 to suppress display of the focus highlight.

10. jump: This option controls what happens when a user drags the slider. Normally (jump=0), every small drag of the slider causes the command callback to be called. If you set this option to 1, the callback isn't called until the user releases the mouse button.

11. orient: Set orient=HORIZONTAL for a horizontal scrollbar, orient=VERTICAL for a vertical one.

12. repeatdelay: This option controls how long button 1 has to be held down in the trough before the slider starts moving in that direction repeatedly. Default is repeatdelay=300, and the units are milliseconds.

13. repeatinterval: repeatinterval

14. takefocus: Normally, you can tab the focus through a scrollbar widget. Set takefocus=0 if you don't want this behavior.

15. troughcolor: The color of the trough.

16. width: Width of the scrollbar (its y dimension if horizontal, and its x dimension if vertical). Default is 16.

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

1. get(): Returns two numbers (a, b) describing the current position of the slider. The a value gives the position of the left or top edge of the slider, for horizontal and vertical scrollbars respectively; the b value gives the position of the right or bottom edge.

2. set ( first, last ): To connect a scrollbar to another widget w, set w's xscrollcommand or yscrollcommand to the scrollbar's set() method. The arguments have the same meaning as the values returned by the get() method.

 

 

 

 

 

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

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

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 楓綺 的頭像
    楓綺

    K_程式人

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