AttributeError when trying to set a window type hint with GTK using Python
<p>I'm still really new to python, so this will probably be a dumb question.</p>

<p>I'm trying to learn how to make a GUI using pygtk (Mostly because I use linux and I'd like to have GTK theming support in my programs). I've started with the most simple window possible, and I've found that since I'm using a tiling window manager the program will be tiled.</p>

<p>This is not a problem, but the first program I wanted to make needs a floating window, and I could fix it client-side modifying the configuration of the window manager, but I'd like to do it right and make it working for everyone.</p>

<p><a href="https://faq.i3wm.org/question/61/forcing-windows-as-always-floating.1.html" rel="nofollow">After some research</a> I've found that the way to do it is by setting a window type hint that the window manager will automatically set as "floating". This is what I've tried, using <a href="http://www.pygtk.org/docs/pygtk/class-gtkwindow.html#method-gtkwindow--set-type-hint" rel="nofollow">this</a> as resource:</p>

<pre><code>import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.set_type_hint(Gtk.gdk.WINDOW_TYPE_HINT_UTILITY)
win.show_all()
Gtk.main()
</code></pre>

<p>But it doesn't work. I get a traceback.</p>

<pre><code>Traceback (most recent call last):
  File "/mnt/storHDD/Programming/Python/python-learning/guitesting.py", line 7, in &lt;module&gt;
    win.set_type_hint(Gtk.gdk.WINDOW_TYPE_HINT_UTILITY)
  File "/usr/lib/python3.5/site-packages/gi/overrides/__init__.py", line 39, in __getattr__
    return getattr(self._introspection_module, name)
  File "/usr/lib/python3.5/site-packages/gi/module.py", line 139, in __getattr__
    self.__name__, name))
AttributeError: 'gi.repository.Gtk' object has no attribute 'gdk'
</code></pre>

<p>I don't really know what to do from here. I've tried to import gdk too, but it doesn't seem to change anything. Any idea about what can I do to solve this?</p>

<p>You need to import <code>Gdk</code>, then use <code>Gdk.WindowTypeHint.UTILITY</code>, not <code>Gtk.gdk.WINDOW_TYPE_HINT_UTILITY</code>:</p>

<pre class="lang-py prettyprint-override"><code>import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk

win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.set_type_hint(Gdk.WindowTypeHint.UTILITY)
win.show_all()
Gtk.main()
</code></pre>

<p><a href="http://i.stack.imgur.com/TKBll.png" rel="nofollow"><img src="http://i.stack.imgur.com/TKBll.png" alt="enter image description here"></a></p>

<p>see also <a href="https://people.gnome.org/~gcampagna/docs/Gdk-3.0/Gdk.WindowTypeHint.html" rel="nofollow">here</a>.</p>

python user-interface gtk