开发者

Python making gtk.Layout with Scrollbars

How could I have a scrollbar inside a gtk.Layout.

For example, in my code I have:

import pygtk
pygtk.require('2.0')
import gtk

class ScrolledWindowExample:
    def __init__(self):
        self.window = gtk.Dialog()
        self.window.connect("destroy", self.destroy)
        self.window.set_size_request(300, 300)

        self.scrolled_window = gtk.ScrolledWindow()
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        self.window.vbox.pack_start(self.scrolled_window, True, True, 0)

        self.layout = gtk.Layout()
        self.scrolled_window.add(self.layout)

        self.current_pos = 0
        self.add_buttom()
        self.window.show_all()

    def add_buttom(self, widget = None):
            title = str(self.current_pos)
            button = gtk.ToggleButton(title)
            button.connect_object("clicked", self.add_buttom, None)
            self.layout.put(button, self.current_pos, self.current_pos)
            button.show()
            self.current_pos += 20

    def destroy(self, widget):
        gtk.main_quit()

if __name__ == "__main__":
    ScrolledWindowExample()
    gtk.main()

What I really want is to find some w开发者_C百科ay to make the scroll dynamic. See the example that I put above, when you click any button, another button will be added. But the scrollbar doesn't work.

What can I do to get the scroll bars working?


Does it works if you either use gtk.Window() instead of gtk.Dialog(); or execute self.window.run() after self.window.show_all()?

The difference between Dialog and common Window is that Dialog has its own loop which processes events. As you do not run its run() command, this loop never gets the chance to catch the events, so ScrolledWindow does not receives them, and does not change its size.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜