gtk_js_hello.js (代码由 deepseek生成 )
// 明确指定使用 GTK 4
imports.gi.versions.Gtk = '4.0';
const { Gtk } = imports.gi;
// 初始化 GTK
Gtk.init();
// 创建应用
const app = new Gtk.Application({
application_id: 'org.example.myapp'
});
// 应用激活时创建窗口
app.connect('activate', () => {
const win = new Gtk.ApplicationWindow({
application: app,
title: 'GTK4 示例',
default_width: 400,
default_height: 300
});
// 添加一个按钮
const button = new Gtk.Button({
label: '点击我',
margin_top: 12,
margin_bottom: 12,
margin_start: 12,
margin_end: 12
});
button.connect('clicked', () => {
print('按钮被