1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#! /usr/bin/env lua
-- vim:sw=4:sts=4
-- Simple example of a window with one button that is destoyed when clicked.
-- It adds another one instead that quits the application.
require "gtk"
-- Avoid main_quit complain about extra parameters. This would happen if
-- you provide gtk.main_quit as handler for the clicked event.
function quit()
gtk.main_quit()
end
--
-- Destroy the button on click, and add a Quit button instead.
-- Note that a Window can only contain one child widget; to have two or more
-- another container would have to be used (like GtkVBox).
--
function make_quit_button_a(button)
button:destroy()
button = gtk.button_new_with_label("Quit")
win:add(button)
button:show()
button:connect('clicked', quit)
end
-- Change the button on click; same effect as the above function.
function make_quit_button_b(button)
button:set_label("Quit")
button:connect('clicked', quit)
end
-- Create the main window.
win = gtk.window_new(gtk.GTK_WINDOW_TOPLEVEL)
win:set_title("Button Demo")
win:move(0, 0)
win:connect('destroy', quit)
win:show()
-- a button that will destroy itself when clicked.
button = gtk.button_new_with_label("Click me")
win:add(button)
button:show()
button:connect('clicked', make_quit_button_a)
gtk.main()
|