I am using PyCharm for doing a application in Gtk. First I tried to automatically install the package but it gave me a dependency error and told me to install the Cairo package and something else that I don't remember to be able to correctly install Gtk.
I'm not going to put all the console logs but if it helps I'll paste them or put a link or something that I have saved.
Anyway, after installing these packages it worked for me.
sudo apt-get install libcairo2-dev
sudo apt-get install build-essential
sudo apt-get install python3-dev
sudo apt install libgirepository1.0-dev
To all this, the pycharm packages that I have in the environment are these and they finally stopped giving me errors
My problem is when I try to compile a simple code like this it gives me an error and I am not able to fix it. I don't know if it is a Gtk problem or something I installed, if I am missing something but I can't get it to work.
Error:
home/user/PycharmProjects/tfg/.venv/bin/python /home/user/PycharmProjects/work/prueba.py Traceback (most recent call last): File "/home/user/PycharmProjects/work/prueba.py", line 7, in class MyWindow(Gtk.Window):
AttributeError: type object 'Gtk' has no attribute 'Window' Process finished with exit code 1
import gi
#gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class MyWindow(Gtk.Window):
def __init__(self):
super().__init__(title="Hello World")
self.button = Gtk.Button(label="Click Here")
self.button.connect("clicked", self.on_button_clicked)
self.add(self.button)
def on_button_clicked(self, widget):
print("Hello World")
def main():
win = MyWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
if __name__ == "__main__":
main() ```


Try adding the system libs for GTK3:
sudo apt install libgtk-3-dev