1class MyWindow : Gtk.ApplicationWindow { 2 3 internal MyWindow (MyApplication app) { 4 Object (application: app, title: "Switch Example"); 5 6 this.set_default_size (300, 100); 7 this.border_width = 10; 8 9 var label = new Gtk.Label ("Title"); 10 var switcher = new Gtk.Switch (); 11 12 switcher.set_active (true); 13 14 switcher.notify["active"].connect (switcher_cb); 15 16 var grid = new Gtk.Grid (); 17 grid.set_column_spacing (10); 18 grid.attach (label, 0, 0, 1, 1); 19 grid.attach (switcher, 1, 0, 1, 1); 20 21 this.add (grid); 22 } 23 24 void switcher_cb (Object switcher, ParamSpec pspec) { 25 if ((switcher as Gtk.Switch).get_active()) 26 this.set_title ("Switch Example"); 27 else 28 this.set_title (""); 29 } 30} 31 32class MyApplication : Gtk.Application { 33 protected override void activate () { 34 35 var window = new MyWindow (this); 36 window.show_all (); //show all the things 37 } 38 39 internal MyApplication () { 40 Object (application_id: "org.example.checkbutton"); 41 } 42} 43 44int main (string[] args) { 45 return new MyApplication ().run (args); 46} 47