一个简单的 GTK 窗口
使用 GTK 和 Python 可以轻松呈现窗口。下面的示例基于 Python GTK3 教程 ,如果你是 GUI 编程或 GTK 的初学者,你应该阅读它。
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Set up the Gtk window
win = Gtk.Window()
# Tell Gtk what to do when the window is closed (in this case quit the main loop)
win.connect("delete-event", Gtk.main_quit)
# Create a label saying Hello World!
label = Gtk.Label(label="Hello World!")
# Add the label to the window
win.add(label)
# Tell Gtk to show all widgets inside the window
win.show_all()
# Start the Gtk main loop, which returns when Gtk.main_quit is called
Gtk.main()
哪个(在 Windows 10 上)会导致: