在Python下使用GTK无法直接使用pip安装PyGObject库
打卡MSYS终端,依次执行:
pacman -Suy
pacman -S mingw-w64-x86_64-gtk4 mingw-w64-x86_64-python3 mingw-w64-x86_64-python3-pip mingw-w64-x86_64-python3-gobject mingw-w64-x86_64-libadwaita mingw-w64-x86_64-python-autopep8 mingw-w64-x86_64-python-pylint
pacman -S python3
python3 --version
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk
def on_activate(app):
win = Gtk.ApplicationWindow(application=app)
btn = Gtk.Button(label="Hello, World!")
btn.connect('clicked', lambda x: win.close())
win.set_child(btn)
win.present()
app = Gtk.Application(application_id='org.gtk.Example')
app.connect('activate', on_activate)
app.run(None)
参考链接
PyObject
Python和Gtk 4:在Windows上准备开发环境