자바스크립트를 이용하여 GNOME에서 창을 띄어보기


출처: YES! Gnome JS Bindings Documentation is now available! 

#!/usr/bin/gjs

//The previous line is a hash bang which tells how to run the script.
// Note that the script has to be executable (run in terminal in the right folder: chmod +x scriptname)
// Initialize GTK+
var Gtk = imports.gi.Gtk;
Gtk.init(null, 0);
// Create your window, name it, and connect the “click x to quit” function.
// The word “window” is a JavaScript keyword, so we have to
// call it something different.
var mywindow = new Gtk.Window({type: Gtk.WindowType.TOPLEVEL});
mywindow.title = "Hello World!";
mywindow.connect("destroy", function(){Gtk.main_quit()});
// Add some text to your window
var label = new Gtk.Label({label: "Hello World"});
mywindow.add(label);
// Make the label and the window itself visible to the user
label.show();
mywindow.show();
// Let the user run the app
Gtk.main();


chmod +x helloworld.js

./helloworld.js


Hello World!



+ Recent posts