读书人

pygtk-报表

发布时间: 2012-10-07 17:28:51 作者: rapoo

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)
pygtk-报表
?
#!/usr/bin/env python# example table.pyimport pygtkpygtk.require("2.0")import gtkclass Table:# Our callback.# The data passed to this method is printed to stdoutdef callback(self, widget, data=None):print "Hello again - %s was pressed" % data# This callback quits the programdef delete_event(self, widget, event, data=None):gtk.main_quit()return Falsedef __init__(self):# Create a new window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)# Set the window titleself.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 tabletable = gtk.Table(2, 2, True)# Put the table in the main windowself.window.add(table)# Create first buttonbutton = gtk.Button("button 1")# When the button is clicked, we call the "callback" method# with a pointer to "button 1" as its argumentbutton.connect("clicked", self.callback, "button 1")# Insert button 1 into the upper left quadrant of the tabletable.attach(button, 0, 1, 0, 1)button.show()# Create second buttonbutton = gtk.Button("button 2")# When the button is clicked, we call the "callback" method# with a pointer to "button 2" as its argumentbutton.connect("clicked", self.callback, "button 2")# Insert button 2 into the upper right quadrant of the tabletable.attach(button, 1, 2, 0, 1)button.show()# Create "Quit" buttonbutton = gtk.Button("Quit")# When the button is clicked, we call the main_quit function# and the program exitsbutton.connect("clicked", lambda w: gtk.main_quit())# Insert the quit button into the both lower quadrants of the tabletable.attach(button, 0, 2, 1, 2)button.show()table.show()self.window.show()def main():        gtk.main()        return 0if __name__ == "__main__":Table()main()  
?

读书人网 >编程

热点推荐