Search code examples
pythonvisual-studio-codeidegtk

How can I enable syntax highlighting, auto-complete etc. for GTK4 in python?


I'm using Visual Studio Code, and I am trying to develop my first application in GTK4 in python. So far, I managed to make some things, but everything without the IDE's help, because everything I try calling from GTK is white, and of type "Any".

import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk


class Window(Gtk.ApplicationWindow):
  def __init__(self, app):
    #...
    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=20) # everything as Any type, and no help from the IDE with syntax highlighting or autocomplete

I tried looking for vs extensions with keywords such as "GTK" and "GTK Python", but none of them seems to be what I need.

So, is there any way to syntax highlight/auto-complete the GTK library in python?


Solution

  • The solution was simply to write:
    pip install pygobject-stubs
    as GTK is compiled dynamically and this repo does the job of assigning the correct class/function signatures