A simple GTK program that demonstrate the constructing of custom button.
1: require 'gtk'2: require 'gdk_pixbuf'3:4: #Returns image from image file5: def load_image_from_file(file_path)6:7: pixbuf = Gdk::Pixbuf.new file_path8:9: pixmap, mask = pixbuf.render_pixmap_and_mask10:11: image = Gtk::Pixmap.new(pixmap, mask)12: end13:14: window = Gtk::Window.new Gtk::WINDOW_TOPLEVEL15:16: window.signal_connect('delete_event') { Gtk.main_quit }17:18: window.border_width 2019:20: window.set_title "Custom button"21:22: button = Gtk::Button.new23:24: vbox = Gtk::VBox.new25:26: button.add vbox27:28: label = Gtk::Label.new "Press the Lion bellow"29:30: vbox.pack_start label31:32: image = load_image "Lion.png"33:34: vbox.pack_start image35:36: window.add button37:38: window.show_all39:40: Gtk.main
Sources:
http://ruby-gnome.sourceforge.net/tutorial/c429.html
http://zetcode.com/tutorials/gtktutorial/gtkevents/
אין תגובות:
הוסף רשומת תגובה