Morton Goldberg
4/3/2007 12:41:00 AM
On Apr 2, 2007, at 6:03 AM, Julian Schnidder wrote:
> In Brent B. Welsh's book "Practical Programming in Tcl and Tk" 4th
> ed. the index redirects "combobox" to "spinbox" (new in Tcl/Tk
> version 8.4 IIRC):
>
> require 'tk'
>
> TkSpinbox.new do
> from -2
> to 2
> pack
> end
>
> TkSpinbox.new do
> from -2
> to 2
> increment 0.1
> pack
> end
>
> TkSpinbox.new do
> @states=["Arizona", "California", "New Mexico"]
> values @states
> wrap 1
> pack
> end
>
> TkButton.new do
> text "Quit"
> command "exit"
> pack
> end
>
> Tk.mainloop
>
> Hope, that helps.
>
> Julian
That's an interesting example, but are spin boxes really the same as
combo boxes? The OP may also want to look at Tk::Iwidgets::Combobox.
Here is a minimal example.
<code>
require 'tk'
require 'tkextlib/iwidgets'
DEBUG = []
COLORS = %w[red green blue cyan yellow magenta black white]
begin
root = TkRoot.new {title 'Ruby/Tk Combo Box'}
cbx = Tk::Iwidgets::Combobox.new(root) {
labeltext "Colors:"
pack :pady => 10
}
cbx.insert_entry(0, COLORS.first)
COLORS.each { |color| cbx.insert_list('end', color) }
btn = TkButton.new do
text "Quit"
command { Tk.root.destroy }
pack
end
win_w, win_h = 300, 80
win_l = (TkWinfo.screenwidth('.') - win_w) / 2
root.geometry("#{win_w}x#{win_h}+#{win_l}+50")
root.resizable(false, false)
# Make Cmnd+Q work as expected on Mac OS X.
root.bind('Command-q') { Tk.root.destroy }
Tk.mainloop
ensure
puts DEBUG unless DEBUG.empty?
end
</code>
Regards, Morton