Last active
August 29, 2015 14:08
-
-
Save toshia/05d5ee302f49677e9d34 to your computer and use it in GitHub Desktop.
Ruby2.1.3p242、gtk2 2.2.2では動かないけど2.2.0では動くカウントアップタイマー
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
#require 'bundler/setup' | |
require 'gtk2' | |
window = Gtk::Window.new | |
w_text = Gtk::Label.new("...") | |
w_btn = Gtk::Button.new("click") | |
counter = 0 | |
window.add(Gtk::VBox.new.add(w_text).add(w_btn)) | |
window.set_size_request(320,320) | |
window.signal_connect(:destroy){ Gtk.main_quit } | |
w_btn.signal_connect(:clicked){ | |
# w_text.set_text("...") | |
# counter = 0 | |
true | |
} | |
window.show_all | |
Thread.new do | |
loop do | |
sleep 1 | |
counter += 1 | |
w_text.set_text(counter.to_s) | |
## 最初はこちらのコードで検証してました | |
# Gtk.idle_add_priority(GLib::PRIORITY_LOW) do | |
# counter += 1 | |
# w_text.set_text(counter.to_s) | |
# false | |
# end | |
end | |
end | |
Gtk.main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment