I am trying to build a small program that loops trough and dynamically
creates a number of buttons. Is there any methods available to remove
already created widgets from the main window?
Lets say I would like to remove one of the buttons below, how could I do
that.
Thanks in advance
@buttons = {}
10.times do |i| @buttons[“button#{i}”] Gtk::Button.new(“button #{i}”)
end
a Gtk::Window can hold only one widget since it’s a Gtk::Bin,
so you used a Container when to which you added the Buttons.
the Container which has an add(widget) method usually also have a
remove(widget) method.
but remove only works for sub classes of Gtk::Container. The simplest
way is to destroy the widget with your_button.destroy. That will
automaticaly remove the widget from its parent.
Cheers
detlef
Am Montag, den 08.10.2007, 22:23 +0300 schrieb Dobai-Pataky Bálint:
but remove only works for sub classes of Gtk::Container. The simplest
way is to destroy the widget with your_button.destroy. That will
automaticaly remove the widget from its parent.
Cheers
detlef
I have put all my buttons in a vBox and I would like to be able to
delete them.
How is this possible?
I dont really get it. I have packed my buttons i a vBox but perhaps I
should have used something else. If someone could provide a snippet with
3 buttons packet in some container and at the click on one of the
buttons another button should be removed/deleted, I would be very
thankful.
I dont really get it. I have packed my buttons i a vBox but perhaps I
should have used something else. If someone could provide a snippet with
3 buttons packet in some container and at the click on one of the
buttons another button should be removed/deleted, I would be very
thankful.
Did not take very long until next problem showed up =(
When I click my button I would like to create a new slot consisting of
one Entry and a normal button. So when myButton is clicked the function
below is running and it is supposed to create only one slot.
What happens is that the first time I click myButton one slot is created
and everything is fine. Then when I want to create one more, two slots
are created. Next time three and so on but what I want is only one new
slot per click. Why is it increased and how do I get rid of it?
Thanks
#pack rows of buttons in to VBox
$vBox.pack_start( @hBoxes["vBox#{e}"], true, true, 0 )
typo here ^^^^^
you’ve created @hBoxes[“hBox#{e}”] but you’re trying to show the entry
called “vBox#{e}”, which I guess is lying around elsewhere…
Gtk style is to create a widget, put it in its container, and then
show it.
in the above you can simplify things by removing all the .show lines and
having a @hBoxes[“hBox#{e}”].show_all at the end.
Thanks for the input Martin and that “VBox” thing was actually a type
error I made yesterday, sorry bout that. The function below is now
exactly the way it is in my program.
My problem remains though. When I click my button that runs this
function the first time it creates a hbox with an entry and a button
just as it is supposed to. The problem is next time I press the button
then it creates two hBoxes with corresponding buttons etc. The next time
4 and so on and I just can not figure out why. I just want it to create
on hBox per click. Even if I set e = constant this still happens?