📅  最后修改于: 2020-11-08 07:54:12             🧑  作者: Mango
此类是gtk.Hscrollbar和gtk.Vscrollbar小部件的抽象基类。两者都与调整对象关联。滚动条的拇指位置由滚动调整控制。调整对象的属性如下使用-
lower | The minimum value of the scroll region |
upper | The maximum value of the scroll region |
value | Represents the position of the scrollbar, which must be between lower and upper |
page_size | Represents the size of the visible scrollable area |
step_increment | Distance to scroll when the small stepper arrows are clicked |
page_increment | Distance to scroll when the Page Up or Page Down keys pressed |
以下程序显示了放置在添加到顶层窗口的VBox中的HScale和HScrollbar小部件。它们每个都与一个调整对象相关联。
adj1 = gtk.Adjustment(0, 0, 101, 0.1, 1, 1)
self.adj2 = gtk.Adjustment(10,0,101,5,1,1)
gtk.HScale窗口小部件是附带adj1的滑块控件。其更新策略,编号和图纸值位置设置如下-
scale1 = gtk.HScale(adj1)
scale1.set_update_policy(gtk.UPDATE_CONTINUOUS)
scale1.set_digits(1)
scale1.set_value_pos(gtk.POS_TOP)
scale1.set_draw_value(True)
gtk.HScrollbar提供水平滚动条。它与adj2对象关联。其更新策略也设置为CONTINUOUS。
self.bar1 = gtk.HScrollbar(self.adj2)
self.bar1.set_update_policy(gtk.UPDATE_CONTINUOUS)
为了显示滚动条的瞬时值,将调整对象adj2的“ value-changed”信号连接到回调函数on_scrolled() 。该函数检索调整对象的value属性,并将其显示在滚动条下方的标签上。
self.adj2.connect("value_changed", self.on_scrolled)
def on_scrolled(self, widget, data = None):
self.lbl2.set_text("HScrollbar value: "+str(int(self.adj2.value)))
观察以下代码-
import gtk
class PyApp(gtk.Window):
def __init__(self):
super(PyApp, self).__init__()
self.set_title("Range widgets Demo")
self.set_default_size(250, 200)
self.set_position(gtk.WIN_POS_CENTER)
adj1 = gtk.Adjustment(0.0, 0.0, 101.0, 0.1, 1.0, 1.0)
self.adj2 = gtk.Adjustment(10,0,101,5,1,1)
scale1 = gtk.HScale(adj1)
scale1.set_update_policy(gtk.UPDATE_CONTINUOUS)
scale1.set_digits(1)
scale1.set_value_pos(gtk.POS_TOP)
scale1.set_draw_value(True)
vb = gtk.VBox()
vb.add(scale1)
lbl1 = gtk.Label("HScale")
vb.add(lbl1)
self.bar1 = gtk.HScrollbar(self.adj2)
self.bar1.set_update_policy(gtk.UPDATE_CONTINUOUS)
vb.add(self.bar1)
self.lbl2 = gtk.Label("HScrollbar value: ")
vb.add(self.lbl2)
self.adj2.connect("value_changed", self.on_scrolled)
self.add(vb)
self.connect("destroy", gtk.main_quit)
self.show_all()
def on_scrolled(self, widget, data=None):
self.lbl2.set_text("HScrollbar value: "+str(int(self.adj2.value)))
if __name__ == '__main__':
PyApp()
gtk.main()
上面的代码将生成以下输出-