-1

I'm trying to create widgets with a loop. This is what I tried :

def set_runways(self, airfield):
        i = 0
        for rwy in airfield['Runways']:
            frame = Gtk.Frame()
            frame.set_label('-'.join([rwy['Runway_1'], rwy['Runway_2']]))
            frame.set_shadow_type(1)

            self.runways_layout.attach(frame, (i / 2), (i % 2), 1, 1)

            rwy_layout = Gtk.Grid()
            frame.add(rwy_layout)

            # Just for testing :
            label = Gtk.Label('Hello, World')
            rwy_layout.attach(label, 0, 0, 1, 1)

I import my runways_layout in my __init__ with self.runways_layout = builder.get_object('runwaysGrid') which is a Gtk.Grid and I call my function after with self.set_runways(airfield). But even with this, my window doesn't show Hello World, I have a blank window... Why ?

I specify that my rwy isn't empty.

Thanks for your help.

EDIT :
Okay I tried this simple thing :

self.runways_layout = builder.get_object('runwaysGrid')

label = Gtk.Label('Coucou')
self.runways_layout.attach(label, 0, 0, 1, 1)

And it doesn't work too... O_o

Louis Etienne
  • 1,302
  • 3
  • 20
  • 37

1 Answers1

-1

Okay I found a solution, I have to do :

self.runways_layout = builder.get_object('runwaysGrid')

label = Gtk.Label('Coucou')
self.runways_layout.attach(label, 0, 0, 1, 1)

label.show()  # Add this and it works...

But why ?

Louis Etienne
  • 1,302
  • 3
  • 20
  • 37
  • what does it mean "why"? read the show(9 and show_all() methods from the reference and you will find out. – gianmt Sep 27 '15 at 14:15
  • In my other window, I don't have to write `label.show()`. I don't understand why. – Louis Etienne Sep 27 '15 at 14:16
  • 1
    show_all() calls show() recursively on all child if it's a container, so it is sufficient to call it once on the main container (usually the main window) to show all widgets. – gianmt Sep 28 '15 at 14:00