pygtk-表格

 

pygtk表格 

table = gtk.Table(rows=1, columns=1, homogeneous=False)

第一个参数是表格的行数,第二个是表格的列数,homogeneous表格的box的大小是否调整成最大的widget的大小。rows=2且colunms=2的表格如下:

 

0               1              2

0+----------+----------+

|

|

|

1+----------+----------+

|

|

|

2+----------+----------+

在表格中放置widget

 

table.attach(child, left_attach, right_attach, top_attach, bottom_attach,
xoptions=EXPAND|FILL, yoptions=EXPAND|FILL, xpadding=0, ypadding=0)

假设你要在一个2*2的表格中,在首行放置widget,则 left_attach = 0,right_attach = 2, top_attach = 0,bottom_attach = 1。x和y字义了放置的选项,可以使用or定义多选项:
FILL表示如果表格单元比widget大一点,widget 在单元中将填充整个房间
SHRINK 表示如果表格widget被分配小些的空间,widgets在窗体的底部被放置和消失
EXPAND导致表格单元被扩展到表格的余下空间
 set_row_spacing() 和set_col_spacing() 在特定的行或列中加空间
table.set_row_spacing(row, spacing)
table.set_col_spacing(column, spacing)
在所有行列中设置加固定空间
table.set_row_spacings(spacing)
table.set_col_spacings(spacing)


 
#!/usr/bin/env python
# example table.py
import pygtk
pygtk.require("2.0")
import gtk
class Table:
	# Our callback.
	# The data passed to this method is printed to stdout
	def callback(self, widget, data=None):
		print "Hello again - %s was pressed" % data
		# This callback quits the program
	def delete_event(self, widget, event, data=None):
		gtk.main_quit()
		return False
	def __init__(self):
		# Create a new window 
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		# Set the window title
		self.window.set_title("Table")
		# Set a handler for delete_event that immediately
		# exits GTK.
		self.window.connect("delete_event", self.delete_event)
		# Sets the border width of the window.
		self.window.set_border_width(20)
		# Create a 2x2 table
		table = gtk.Table(2, 2, True)
		# Put the table in the main window
		self.window.add(table)
		# Create first button
		button = gtk.Button("button 1")
		# When the button is clicked, we call the "callback" method
		# with a pointer to "button 1" as its argument
		button.connect("clicked", self.callback, "button 1")
		# Insert button 1 into the upper left quadrant of the table
		table.attach(button, 0, 1, 0, 1)
		button.show()
		# Create second button
		button = gtk.Button("button 2")
		# When the button is clicked, we call the "callback" method
		# with a pointer to "button 2" as its argument
		button.connect("clicked", self.callback, "button 2")
		# Insert button 2 into the upper right quadrant of the table
		table.attach(button, 1, 2, 0, 1)
		button.show()
		# Create "Quit" button
		button = gtk.Button("Quit")
		# When the button is clicked, we call the main_quit function
		# and the program exits
		button.connect("clicked", lambda w: gtk.main_quit())
		# Insert the quit button into the both lower quadrants of the table
		table.attach(button, 0, 2, 1, 2)
		button.show()
		table.show()
		self.window.show()
def main():
        gtk.main()
        return 0
if __name__ == "__main__":
	Table()
	main() 
 
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值