# Focus a Gtk::Window?

**URL:** <https://www.ruby-forum.com/t/focus-a-gtk-window/115199>\
**Category:** Ruby-Gnome 2\
**Created:** [September 21, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/focus-a-gtk-window/115199 "2007-09-21T16:57:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [September 21, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/focus-a-gtk-window/115199/1 "2007-09-21T16:57:39Z")

</div>

Hello,

How can I focus an existing Gtk::Window inside my application? A little  
example:

########################  
require ‘gtk2’  
secondwindow = nil

button = Gtk::Button.new(“Click me”)  
button.signal\_connect(“clicked”){  
if secondwindow == nil or secondwindow.destroyed?  
secondwindow = Gtk::Window.new  
secondwindow.show\_all  
else  
# I want to focus the existing window here  
end  
}

window = Gtk::Window.new  
window.add button  
window.show\_all  
Gtk.main  
########################

When you click on the button once, it opens a new Gtk::Window. When you  
click on it a second time, I want the existing window to be focused.  
Making the second window modal is not an option for me here.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [September 21, 2007, 7:16pm UTC](https://www.ruby-forum.com/t/focus-a-gtk-window/115199/2 "2007-09-21T19:16:35Z")

</div>

On Fri, Sep 21, 2007 at 04:57:39PM +0200, Joachim G. wrote:

> Hello,
> 
> How can I focus an existing Gtk::Window inside my application? A little

secondwindow.present should do what you want. See:

[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AWindow#present](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AWindow#present)

-pete

* * *

This [SF.net](http://SF.net) email is sponsored by: Microsoft  
Defy all challenges. Microsoft(R) Visual Studio 2005.  
[http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/](http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/)

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [September 22, 2007, 3:37pm UTC](https://www.ruby-forum.com/t/focus-a-gtk-window/115199/3 "2007-09-22T15:37:27Z")

</div>

Peter J. wrote:

> On Fri, Sep 21, 2007 at 04:57:39PM +0200, Joachim G. wrote:
> 
> > Hello,
> > 
> > How can I focus an existing Gtk::Window inside my application? A little
> 
> secondwindow.present should do what you want. See:
> 
> [http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AWindow#present](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AWindow#present)  
> Yes, thank you, that’s exactly what I was searching for.
