# New to gui-coding and have 2 questions :)

**URL:** <https://www.ruby-forum.com/t/new-to-gui-coding-and-have-2-questions/120481>\
**Category:** Ruby-Gnome 2\
**Created:** [November 17, 2007, 12:08pm UTC](https://www.ruby-forum.com/t/new-to-gui-coding-and-have-2-questions/120481 "2007-11-17T12:08:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [November 17, 2007, 12:08pm UTC](https://www.ruby-forum.com/t/new-to-gui-coding-and-have-2-questions/120481/1 "2007-11-17T12:08:52Z")

</div>

Hi,  
I started to code my first gui with ruby and gtk with the help of glade.  
Now everything works fine but I have two problems:

1.) If I exit my program via the X in the window-border (I hope you  
understand what I mean. The X which is in every window in the  
right-upper border) the window closes but the program keeps running. So  
if I execute it in the console I have to push strg+c to make my process  
end. How can I make my program finish if I push the X on the window?

2.) How do I invoka an error-dialog box? I know how to create one with  
glade but how can I call it?

Any help is really welcome 🙂

## greets

kazaam [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [November 17, 2007, 4:34pm UTC](https://www.ruby-forum.com/t/new-to-gui-coding-and-have-2-questions/120481/2 "2007-11-17T16:34:57Z")

</div>

kazaam  
escribió:\> Hi,

> I started to code my first gui with ruby and gtk with the help of glade. Now everything works fine but I have two problems:
> 
> 1.) If I exit my program via the X in the window-border (I hope you understand what I mean. The X which is in every window in the right-upper border) the window closes but the program keeps running. So if I execute it in the console I have to push strg+c to make my process end. How can I make my program finish if I push the X on the window?

That X in the right-upper corner triggers a delete-event.

In glade-2, in the signals tab of your main window, add an event for the  
signal delete\_event, then add in your ruby file a code similar to:

```
def on_YOURWINDOW_delete_event widget, event, data = nil
    Gtk.main_quit
end

```

where YOURWINDOW is the widget name (in this case the main window)

> 2.) How do I invoka an error-dialog box? I know how to create one with glade but how can I call it?

glade-2 allows to create Dialogs, in the same way as you create Windows.  
Try YOURDIALOG.run for showing it as explained in  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ADialog#run](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ADialog#run)

For error/warn/info dialogs, the best way seems to create a  
Gtk::MessageDialog, as shown in  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AMessageDialog](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AMessageDialog)

> Any help is really welcome 🙂
> 
> greets

–

Regards,  
Cro

---

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [November 17, 2007, 5:31pm UTC](https://www.ruby-forum.com/t/new-to-gui-coding-and-have-2-questions/120481/3 "2007-11-17T17:31:50Z")

</div>

On Sat, 17 Nov 2007 12:34:19 -0300  
El Croata [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> def on_YOURWINDOW_delete_event widget, event, data = nil
> Gtk.main_quit
> end
> 
> ```
> 
> where YOURWINDOW is the widget name (in this case the main window)

Ahh thanks I tried it with the destroy-signal but with the delete one it  
works now 🙂

> glade-2 allows to create Dialogs, in the same way as you create Windows.  
> Try YOURDIALOG.run for showing it as explained in  
> [http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ADialog#run](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ADialog#run)
> 
> For error/warn/info dialogs, the best way seems to create a  
> Gtk::MessageDialog, as shown in  
> [http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AMessageDialog](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AMessageDialog)

I created now a dialog with one button with glade and set it to  
invisible. If I wanna raise it I just call it with dialog1.show which  
work correctly.

thanks for your help

## greets

kazaam [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
