Reputation: 177
I'm still really new to python, so this will probably be a dumb question.
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.
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.
After some research 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 this as resource:
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()
But it doesn't work. I get a traceback.
Traceback (most recent call last):
File "/mnt/storHDD/Programming/Python/python-learning/guitesting.py", line 7, in <module>
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'
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?
Upvotes: 2
Views: 1113
Reputation: 3159
You need to import Gdk
, then use Gdk.WindowTypeHint.UTILITY
, not Gtk.gdk.WINDOW_TYPE_HINT_UTILITY
:
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()
see also here.
Upvotes: 4