pygtk-ScrolledWindow

#!/usr/bin/env python

# example scrolledwin.py

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

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

    def __init__(self):
        # Create a new dialog window for the scrolled window to be
        # packed into.
        window = gtk.Dialog()
        window.connect("destroy", self.destroy)
        window.set_title("ScrolledWindow example")
        window.set_border_width(0)
        window.set_size_request(300, 300)

        # create a new scrolled window.
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_border_width(10)

        # the policy is one of POLICY AUTOMATIC, or POLICY_ALWAYS.
        # POLICY_AUTOMATIC will automatically decide whether you need
        # scrollbars, whereas POLICY_ALWAYS will always leave the scrollbars
        # there. The first one is the horizontal scrollbar, the second, the
        # vertical.
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)

        # The dialog window is created with a vbox packed into it.
        window.vbox.pack_start(scrolled_window, True, True, 0)
        scrolled_window.show()

        # create a table of 10 by 10 squares.
        table = gtk.Table(10, 10, False)

        # set the spacing to 10 on x and 10 on y
        table.set_row_spacings(10)
        table.set_col_spacings(10)

        # pack the table into the scrolled window
        scrolled_window.add_with_viewport(table)
        table.show()

        # this simply creates a grid of toggle buttons on the table
        # to demonstrate the scrolled window.
        for i in range(10):
            for j in range(10):
                buffer = "button (%d,%d)" % (i, j)
                button = gtk.ToggleButton(buffer)
                table.attach(button, i, i+1, j, j+1)
                button.show()

        # Add a "close" button to the bottom of the dialog
        button = gtk.Button("close")
        button.connect_object("clicked", self.destroy, window)

        # this makes it so the button is the default.
        button.set_flags(gtk.CAN_DEFAULT)
        window.action_area.pack_start( button, True, True, 0)

        # This grabs this button to be the default button. Simply hitting
        # the "Enter" key will cause this button to activate.
        button.grab_default()
        button.show()
        window.show()

def main():
    gtk.main()
    return 0

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

 



 

scrolled_window.set_policy(hscrollbar_policy, vscrollbar_policy)

 

其中policy是:POLICY_AUTOMATIC 或 POLICY_ALWAYS. POLICY_AUTOMATIC

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值