一個簡單的 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 上)會導致:

StackOverflow 文件