2014-07-16 53 views
0

如何在python3中設置Gtk.ScrolledWindow的垂直調整?這是一個演示問題的例子。如何設置Gtk.ScrolledWindow調整

#!/usr/bin/env python3 

from gi.repository import Gtk 

class window: 
    def __init__(self): 
     win = Gtk.Window() 
     win.connect("delete_event", Gtk.main_quit) 
     win.set_default_size(300,100) 
     scroll = Gtk.ScrolledWindow(None, None) 
     view = Gtk.Viewport(None, None) 
     label = Gtk.Label('a\n\n\n\n\nb\n\n\n\n\n\n\n\nc') 
     view.add(label) 
     scroll.add(view) 
     position = Gtk.Adjustment(value=50) 
     scroll.set_vadjustment(position) 
     win.add(scroll) 
     win.show_all() 


if __name__ == '__main__': 
    win = window() 
    Gtk.main() 

回答

0

luciomrx的答案是正確的,但首先需要找出值。因此,使用get_vadjustment()set_value()更容易。此外,該set_vadjustment()具有後show_all()

這是它的工作原理,進行執行:

from gi.repository import Gtk 

class window: 
    def __init__(self): 
     win = Gtk.Window() 
     win.connect("delete_event", Gtk.main_quit) 
     win.set_default_size(300,100) 
     scroll = Gtk.ScrolledWindow(None, None) 
     view = Gtk.Viewport(None, None) 
     label = Gtk.Label('a\n\n\n\n\nb\n\n\n\n\n\n\n\nc') 
     view.add(label) 
     scroll.add(view) 
     win.add(scroll) 
     win.show_all() 
     position = scroll.get_vadjustment() 
     position.set_value(50) 
     scroll.set_vadjustment(position) 


if __name__ == '__main__': 
    win = window() 
    Gtk.main() 
0

通常他們通過None。如果你想調整自己,只需創建一個新的Gtk.Adjustment對象。 Gtk.Adjustment(初始值,最小值,最大值,步進增量,頁面增量,頁面大小)

+0

你能否提供一些代碼是如何做到這一點在我上面顯示的例子嗎? – elya5

相關問題