Table¶
Note
Gtk.Table
has been deprecated since GTK+ version 3.4 and should not be used in
newly-written code. Use the Grid class instead.
Tables allows us to place widgets in a grid similar to Gtk.Grid
.
The grid’s dimensions need to be specified in the Gtk.Table
constructor.
To place a widget into a box, use Gtk.Table.attach()
.
Gtk.Table.set_row_spacing()
and
Gtk.Table.set_col_spacing()
set the spacing between the rows at the
specified row or column. Note that for columns, the space goes to the right
of the column, and for rows, the space goes below the row.
You can also set a consistent spacing for all rows and/or columns with
Gtk.Table.set_row_spacings()
and Gtk.Table.set_col_spacings()
.
Note that with these calls, the last row and last column do not get any spacing.
Deprecated since version 3.4: It is recommended that you use the Gtk.Grid
for new code.
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class TableWindow(Gtk.Window):
def __init__(self):
super().__init__(title="Table Example")
table = Gtk.Table(n_rows=3, n_columns=3, homogeneous=True)
self.add(table)
button1 = Gtk.Button(label="Button 1")
button2 = Gtk.Button(label="Button 2")
button3 = Gtk.Button(label="Button 3")
button4 = Gtk.Button(label="Button 4")
button5 = Gtk.Button(label="Button 5")
button6 = Gtk.Button(label="Button 6")
table.attach(button1, 0, 1, 0, 1)
table.attach(button2, 1, 3, 0, 1)
table.attach(button3, 0, 1, 1, 3)
table.attach(button4, 1, 3, 1, 2)
table.attach(button5, 1, 2, 2, 3)
table.attach(button6, 2, 3, 2, 3)
win = TableWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
|