3
# [SNIPPET_NAME: Layout]
4
# [SNIPPET_CATEGORIES: PyGTK]
5
# [SNIPPET_DESCRIPTION: A simple widget layout example]
15
def WindowDeleteEvent(self, widget, event):
16
# return false so that window will be destroyed
19
def WindowDestroy(self, widget, *data):
23
def ButtonClicked(self, button):
25
self.layout.move(button, random.randint(0,500),
26
random.randint(0,500))
29
# create the top level window
30
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
31
window.set_title("Layout Example")
32
window.set_default_size(300, 300)
33
window.connect("delete-event", self.WindowDeleteEvent)
34
window.connect("destroy", self.WindowDestroy)
35
# create the table and pack into the window
36
table = gtk.Table(2, 2, False)
38
# create the layout widget and pack into the table
39
self.layout = gtk.Layout(None, None)
40
self.layout.set_size(600, 600)
41
table.attach(self.layout, 0, 1, 0, 1, gtk.FILL|gtk.EXPAND,
42
gtk.FILL|gtk.EXPAND, 0, 0)
43
# create the scrollbars and pack into the table
44
vScrollbar = gtk.VScrollbar(None)
45
table.attach(vScrollbar, 1, 2, 0, 1, gtk.FILL|gtk.SHRINK,
46
gtk.FILL|gtk.SHRINK, 0, 0)
47
hScrollbar = gtk.HScrollbar(None)
48
table.attach(hScrollbar, 0, 1, 1, 2, gtk.FILL|gtk.SHRINK,
49
gtk.FILL|gtk.SHRINK, 0, 0)
50
# tell the scrollbars to use the layout widget's adjustments
51
vAdjust = self.layout.get_vadjustment()
52
vScrollbar.set_adjustment(vAdjust)
53
hAdjust = self.layout.get_hadjustment()
54
hScrollbar.set_adjustment(hAdjust)
55
# create 3 buttons and put them into the layout widget
56
button = gtk.Button("Press Me")
57
button.connect("clicked", self.ButtonClicked)
58
self.layout.put(button, 0, 0)
59
button = gtk.Button("Press Me")
60
button.connect("clicked", self.ButtonClicked)
61
self.layout.put(button, 100, 0)
62
button = gtk.Button("Press Me")
63
button.connect("clicked", self.ButtonClicked)
64
self.layout.put(button, 200, 0)
65
# show all the widgets
73
if __name__ == "__main__":