/GTK3 - RadioButton
gem install gtk3
RadioButton
라디오 버튼은 한 버튼을 누를 때 다른 버튼을 누르지 않은 상태로 변하며 항상 한 버튼만 누릅니다.
Button 1 was turned off
Button 2 was turned on
Button 2 was turned off
Button 1 was turned on
Button 1 was turned off
Button 3 was turned onrequire 'gtk3'
class RadioButtonWindow < Gtk::Window
def initialize
super
set_title 'RadioButton Demo'
set_border_width 10
hbox = Gtk::Box.new(:horizontal, 6)
add hbox
button1 = Gtk::RadioButton.new(label: 'Button 1')
button1.signal_connect('toggled') { |b| on_button_toggled b, 1 }
hbox.pack_start(button1)
button2 = Gtk::RadioButton.new(member: button1, label: 'Button 2')
button2.signal_connect('toggled') { |b| on_button_toggled b, 2 }
hbox.pack_start(button2)
button3 = Gtk::RadioButton.new(member: button1, label: 'B_utton 3',
use_underline: true)
button3.signal_connect('toggled') { |b| on_button_toggled b, 3 }
hbox.pack_start(button3)
end
def on_button_toggled(button, name)
state = button.active? ? 'on' : 'off'
puts "Button #{name} was turned #{state}"
end
end
win = RadioButtonWindow.new
win.signal_connect('destroy') { Gtk.main_quit }
win.show_all
Gtk.main
참, member
와use_underline
등 루비/GTK3의 특징적인 옵션은 어디에서 정의됩니까?
https://github.com/ruby-gnome/ruby-gnome/blob/master/gtk3/lib/gtk3/radio-button.rb
보아하니 이것들은 수동으로 정의된 것 같다.
require 'gtk3'
class RadioButtonWindow < Gtk::Window
def initialize
super
set_title 'RadioButton Demo'
set_border_width 10
hbox = Gtk::Box.new(:horizontal, 6)
add hbox
button1 = Gtk::RadioButton.new(label: 'Button 1')
button1.signal_connect('toggled') { |b| on_button_toggled b, 1 }
hbox.pack_start(button1)
button2 = Gtk::RadioButton.new(member: button1, label: 'Button 2')
button2.signal_connect('toggled') { |b| on_button_toggled b, 2 }
hbox.pack_start(button2)
button3 = Gtk::RadioButton.new(member: button1, label: 'B_utton 3',
use_underline: true)
button3.signal_connect('toggled') { |b| on_button_toggled b, 3 }
hbox.pack_start(button3)
end
def on_button_toggled(button, name)
state = button.active? ? 'on' : 'off'
puts "Button #{name} was turned #{state}"
end
end
win = RadioButtonWindow.new
win.signal_connect('destroy') { Gtk.main_quit }
win.show_all
Gtk.main
Reference
이 문제에 관하여(/GTK3 - RadioButton), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kojix2/items/5d45d70c98b41763cffc텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)