El contenedor Fixed (Fijo) te permite colocar controles en una posición fija dentro de su ventana, relativa a su esquina superior izquierda. La posición de los controles se puede cambiar dinámicamente.
Sólo hay dos llamadas asociadas al control fijo:
fixed = gtk.Fixed() fixed.put(widget, x, y) fixed.move(widget, x, y) |
La función gtk.Fixed() te permite crear un nuevo contenedor Fixed .
El método put() coloca al control en el contenedor fijo en la posición especificada por x e y.
El método move() te permite mover el control especificado a una nueva posición.
El ejemplo fixed.py ilustra cómo usar el contenedor Fixed . La figura Figura 10.2. Ejemplo de Fijo muestra el resultado:
El código fuente de fixed.py es:
1 #!/usr/bin/env python
2
3 # example fixed.py
4
5 import gtk
6
7 class FixedExample:
8 # This callback method moves the button to a new position
9 # in the Fixed container.
10 def move_button(self, widget):
11 self.x = (self.x+30)%300
12 self.y = (self.y+50)%300
13 self.fixed.move(widget, self.x, self.y)
14
15 def __init__(self):
16 self.x = 50
17 self.y = 50
18
19 # Create a new window
20 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
21 window.set_title("Fixed Container")
22
23 # Here we connect the "destroy" event to a signal handler
24 window.connect("destroy", gtk.mainquit)
25
26 # Sets the border width of the window.
27 window.set_border_width(10)
28
29 # Create a Fixed Container
30 self.fixed = gtk.Fixed()
31 window.add(self.fixed)
32 self.fixed.show()
33
34 for i in range(1, 4):
35 # Creates a new button with the label "Press me"
36 button = gtk.Button("Press me")
37
38 # When the button receives the "clicked" signal, it will call the
39 # method move_button().
40 button.connect("clicked", self.move_button)
41
42 # This packs the button into the fixed containers window.
43 self.fixed.put(button, i*50, i*50)
44
45 # The final step is to display this newly created widget.
46 button.show()
47
48 # Display the window
49 window.show()
50
51 def main():
52 # Enter the event loop
53 gtk.main()
54 return 0
55
56 if __name__ == "__main__":
57 FixedExample()
58 main()
|