Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Ruby/TKでRubyからGUIを表示

概要

Ruby/TKでRubyからGUIを表示

内容

Ruby/TKでRubyからGUIを表示します。

サンプル

前提

Windows用のrubyinstaller-1.9.3-p0.exeを使用して
RubyWindows7環境にインストール済みとする。

コード
# encoding: utf-8
require 'tk'

TkLabel.new do
  text "伝   令"
  font TkFont.new('times 20 bold italic')
  width 20
  height 2
  bd 5
  relief "groove"
  pack
end

TkLabel.new do
  text "Finish!!"
  font TkFont.new('times 20 bold italic')
  width 20
  height 4
  bd 5
  relief "groove"
  pack
end

root = TkRoot.new
btn_OK = TkButton.new(root) do
  text "close"
  width 10
  focus
  borderwidth 5
  underline 0
  state "normal"
  cursor "hand2"
  font TkFont.new('times 20 bold')
  foreground  "red"
  activebackground "blue"
  relief      "raised"
  command {exit}
  pack("side" => "right",  "padx"=> "50", "pady"=> "10")
end

Tk.mainloop

実行結果