Ruby/tk Widget
私は会社で、ちょっとしたプログラムにRubyを使用していますが、
GUIでtkを使ってみると、意外と簡単にできたものの、
Webでの資料がPerl等に比べ少ないです。
その辺りをメモ程度で纏めようと思います。
[参考URL]
ActiveTcl 8.5 Documentation
I love Programming
もっとTcl/Tk
- HelloWorld(base)
以下requireとTk.mainloopを削除
require 'tk'TkLabel.new(nil, :text=>"HelloWorld").pack
Tk.mainloop
- Tk.messageBox
state=Tk.messageBox(:message=>"message", :type=>:yesno, :icon=>:question)
case state
when "yes"
#yesの場合の処理
when "no"
#noの場合の処理
end
- TkButton
def temp
puts "temp"
endTkButton.new(nil, :text=>'puts "open"', :command=>proc{puts "open"}).pack(:fill=>:x)
TkButton.new(nil, :text=>"def temp()", :command=>proc{temp()}).pack(:fill=>:x)
TkButton.new(nil, :text=>"close", :command=>proc{exit()}).pack(:fill=>:x)
method
- :text=>""
- :height=>高さ
- :width=>幅
- :command=>
- TkCheckButton
TkCheckButton.new(nil, :text=>"ruby", :command=>proc{puts "ruby"}).pack(:side=>:left)
TkCheckButton.new(nil, :text=>"python", :command=>proc{puts "python"}).pack(:side=>:left)
TkCheckButton.new(nil, :text=>"perl", :command=>proc{puts "perl"}).pack(:side=>:left)
method
- TkListbox
- TkScrollbar
module ExtendListBox
def set(list, array)
array.each_index{|i|
list.insert(i,array[i])
}
end
def get(list, array)
return list.get(0,list.size)
end
def del(list)
list.delete(0,list.size)
end
endinclude ExtendListBox
TkFrame.new{|f|
scr_x = TkScrollbar.new(f).pack(:side=>:bottom, :fill=>:x)
scr_y = TkScrollbar.new(f).pack(:side=>:right, :fill=>:y)
list = TkListbox.new(f).pack(:side=>:right, :fill=>:x)
a = [1,2,3,4,5,6,7,8,9,10]
set(list,a)
list.xscrollbar( scr_x )
list.yscrollbar( scr_y )
}.pack(:fill=>:y)
- TkMenubar
menu_spec=[
]
TkMenubar.new(nil, menu_spec, :tearoff=>false)
- Tk.getOpenFile
Tk.getOpenFile(:filetypes=>filetypes, :parent=>self)
- template
#source
method
- template
#source
method
- template
#source
- 作者: Dave Thomas,Chad Fowler,Andy Hunt,まつもとゆきひろ,田和勝
- 出版社/メーカー: オーム社
- 発売日: 2006/08/26
- メディア: 大型本
- 購入: 7人 クリック: 270回
- この商品を含むブログ (152件) を見る