KChaloux
KChaloux

Reputation: 4058

GTK Nested Boxes

For fun, I decided to pick up Ruby and do some things in GTK. It's pretty much entirely new to me, but I've gotten the hang of the basics.

At the moment, I can't figure out how to properly nest a box within another box. For example, I have something along the lines of:

window = Gtk::Window.new

main_box = Gtk::HBox.new(false, 2)
left_box = Gtk::VBox.new(false, 2)
right_box = Gtk::VBox.new(false, 2)

main_box.pack_start(left_box, true, true, 0)
main_box.pack_start(right_box, true, true, 0)

window.add(main_box)

Off the top of my head, something like that should create a layout with two vertical boxes laid out side-by-side. I keep getting an error when trying to pack the boxes.

undefined method 'pack_start' for nil:NilClass (no method error)

I'm thinking that maybe I can't pack an empty box that doesn't yet include any widgets? Is there something I need to do to explicitly instantiate the boxes?

Upvotes: 1

Views: 351

Answers (2)

user1182000
user1182000

Reputation: 1635

You may want to try visualruby to avoid having to hand-code your boxes. Its still in development stages now, but I'll be uploading a new version very soon. Go to:

http://visualruby.net

Upvotes: 0

KChaloux
KChaloux

Reputation: 4058

I have a motto when it comes to debugging. It's always something stupid

And in this case it was. In my actual code, I was using a box called main_parition, a misspelling of main_partition that I didn't catch for an inexcusably long time.

So to answer my own question, yes, I was failing to instantiate my box, because I was calling it by a slightly different name than the one I created it with. And Ruby doesn't check that for you.

Moral to the story: Always make sure your variable names are correct, especially in languages that don't check for you.

Upvotes: 1

Related Questions