2

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?

3
  • pygtk is not Gtk3. Whenever you see pygtk code, it's likely outdated and won't work with Gtk3. gtk.gdk is an example of that. Commented Aug 31, 2016 at 12:23
  • Sorry, I didn't. Thanks for the answer though. Since according to Rawing this is because pygtk is outdated is there any better way to do things? Commented Aug 31, 2016 at 13:22
  • This seems perfect to me! Commented Aug 31, 2016 at 13:30

1 Answer 1

4

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()

enter image description here

see also here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.