Tkinter Scrollbar(垂直滚动部件)

Python GUI - Tkinter Scrollbar:这个小工具提供了一个幻灯片控制器,用于实现垂直滚动部件,如列表框,文本和帆布。请注意,您还可以创建进入部件的水平滚动条
 
这个小工具提供了一个幻灯片控制器,用于实现垂直滚动部件,如列表框,文本和帆布。请注意,您还可以创建进入部件的水平滚动条.

语法:

这里是一个简单的语法来创建这个widget:

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

参数:

  • master: 这代表了父窗口.

  • options: 下面是这个小工具最常用的选项列表。这些选项可以作为键 - 值对以逗号分隔.

OptionDescription
activebackgroundThe color of the slider and arrowheads when the mouse is over them.
bgThe color of the slider and arrowheads when the mouse is not over them.
bdThe 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.
commandA procedure to be called whenever the scrollbar is moved.
cursorThe cursor that appears when the mouse is over the scrollbar.
elementborderwidthThe width of the borders around the arrowheads and slider. The default is elementborderwidth=-1, which means to use the value of the borderwidth option.
highlightbackgroundThe color of the focus highlight when the scrollbar does not have focus.
highlightcolorThe color of the focus highlight when the scrollbar has the focus.
highlightthicknessThe thickness of the focus highlight. Default is 1. Set to 0 to suppress display of the focus highlight.
jumpThis 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.
orientSet orient=HORIZONTAL for a horizontal scrollbar, orient=VERTICAL for a vertical one.
repeatdelayThis 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.
repeatintervalrepeatinterval
takefocusNormally, you can tab the focus through a scrollbar widget. Set takefocus=0 if you don't want this behavior.
troughcolorThe color of the trough.
widthWidth of the scrollbar (its y dimension if horizontal, and its x dimension if vertical). Default is 16.

Methods:

Scrollbar objects have these methods:

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

例子:

自行尝试下面的例子:

from Tkinter import *

root = Tk()
scrollbar = Scrollbar(root)
scrollbar.pack( side = RIGHT, fill=Y )

mylist = Listbox(root, yscrollcommand = scrollbar.set )
for line in range(100):
   mylist.insert(END, "This is line number " + str(line))

mylist.pack( side = LEFT, fill = BOTH )
scrollbar.config( command = mylist.yview )

mainloop()

这将产生以下结果:

 

转载于:https://www.cnblogs.com/tkinter/p/5628839.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值