Combo boxes in Ruby-Tk

Discussion in 'Ruby' started by Rosalind Mitchell, Mar 30, 2007.

  1. I'm a newcomer to Ruby, though a seasoned campaigner in Perl, and I'm
    finding my feet, so please be nice!

    I've been playing around with the Tk extension. The section on Ruby Tk in
    the pickaxe book is sketchy to say the least. I do have a well-thumbed
    copy of Learning Perl/Tk, so I know my way around the basics.

    My question is: is there any way in Ruby Tk to implement combo boxes?
    Neither BrowseEdit nor JComboBox seem to work.

    Rosie
    Rosalind Mitchell, Mar 30, 2007
    #1
    1. Advertising

  2. Rosalind Mitchell wrote:

    > I'm a newcomer to Ruby, though a seasoned campaigner in Perl, and I'm
    > finding my feet, so please be nice!
    >
    > I've been playing around with the Tk extension. The section on Ruby Tk in
    > the pickaxe book is sketchy to say the least. I do have a well-thumbed
    > copy of Learning Perl/Tk, so I know my way around the basics.
    >
    > My question is: is there any way in Ruby Tk to implement combo boxes?
    > Neither BrowseEdit nor JComboBox seem to work.
    >
    > Rosie


    I'm a little surprised that nobody managed to come up with an answer to
    this.

    Is Tk really a hopeless case with Ruby? If it is, what alternative GUI
    manager would you suggest?

    Rosie
    Rosalind Mitchell, Apr 2, 2007
    #2
    1. Advertising

  3. Hi!

    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


    Am 02.04.2007 um 10:55 schrieb Rosalind Mitchell:

    > Rosalind Mitchell wrote:
    >
    >> I'm a newcomer to Ruby, though a seasoned campaigner in Perl, and I'm
    >> finding my feet, so please be nice!
    >>
    >> I've been playing around with the Tk extension. The section on
    >> Ruby Tk in
    >> the pickaxe book is sketchy to say the least. I do have a well-
    >> thumbed
    >> copy of Learning Perl/Tk, so I know my way around the basics.
    >>
    >> My question is: is there any way in Ruby Tk to implement combo
    >> boxes?
    >> Neither BrowseEdit nor JComboBox seem to work.
    >>
    >> Rosie

    >
    > I'm a little surprised that nobody managed to come up with an
    > answer to
    > this.
    >
    > Is Tk really a hopeless case with Ruby? If it is, what alternative
    > GUI
    > manager would you suggest?
    >
    > Rosie
    >
    >
    >
    Julian Schnidder, Apr 2, 2007
    #3
  4. 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
    Morton Goldberg, Apr 3, 2007
    #4
  5. From: Morton Goldberg <>
    Subject: Re: Combo boxes in Ruby-Tk
    Date: Tue, 3 Apr 2007 09:41:03 +0900
    Message-ID: <>
    > 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.


    Please see 'ext/sample/tkcombobox.rb' on Ruby source tree also. ;-)
    --
    Hidetoshi NAGAI ()
    Hidetoshi NAGAI, Apr 3, 2007
    #5
  6. Morton Goldberg wrote:

    > 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.


    Thank you - that seems to do the trick.

    Rosie
    Rosalind Mitchell, Apr 3, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mithun Verma

    Combo Boxes in Crystal Reports

    Mithun Verma, Jul 5, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    451
    Mithun Verma
    Jul 5, 2003
  2. Steve Chatham

    neaten-ing Combo boxes question

    Steve Chatham, Feb 19, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    369
    =?Utf-8?B?QmFycnkgRm9ycmVzdA==?=
    Feb 19, 2004
  3. Toff McGowen

    ViewState vrs Datagrid Combo Boxes

    Toff McGowen, Nov 15, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    376
    Toff McGowen
    Nov 15, 2005
  4. dthmtlgod

    Fill Combo Box based on another Combo Box

    dthmtlgod, Nov 16, 2005, in forum: ASP General
    Replies:
    1
    Views:
    568
    Bob Barrows [MVP]
    Nov 16, 2005
  5. SM
    Replies:
    2
    Views:
    352
Loading...

Share This Page