/GTK3 - Button

5187 단어 GTK3gtkRuby
gem install gtk3

Button



"Click me"button was clicked
"Open"button was clicked
Closing application
require 'gtk3'

class ButtonWindow < Gtk::Window
  def initialize
    super
    set_title 'Button Demo'
    set_border_width 10

    hbox = Gtk::Box.new(:horizontal, spacing = 6)
    add(hbox)

    button = Gtk::Button.new(label: 'Click Me')
    button.signal_connect('clicked') { on_click_me_clicked }
    hbox.pack_start(button)

    button = Gtk::Button.new(mnemonic: '_Open')
    button.signal_connect('clicked') { on_open_clicked }
    hbox.pack_start(button)

    button = Gtk::Button.new(mnemonic: '_Close')
    button.signal_connect('clicked') { on_close_clicked }
    hbox.pack_start(button)
  end

  def on_click_me_clicked
    puts '"Click me" button was clicked'
  end

  def on_open_clicked
    puts '"Open" button was clicked'
  end

  def on_close_clicked
    puts 'Closing application'
    Gtk.main_quit
  end
end

win = ButtonWindow.new
win.signal_connect('destroy') { Gtk.main_quit }
win.show_all
Gtk.main
  • https://python-gtk-3-tutorial.readthedocs.io/en/latest/button_widgets.html
  • 좋은 웹페이지 즐겨찾기