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)

#!/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() ?