Ruby/TK - ComboBox Widget



Description

A Combobox combines an entry with a list of choices available to the user. This lets them either choose from a set of values you've provided (e.g., typical settings), but also put in their own value.

Syntax

Here is a simple syntax to create this widget −

combobox = TkCombobox.new(root) {
   .....Options....
}

Options

Combobox combines the options related to TkEntry and TkListbox widgets.

Event Bindings

Combobox inherits event bindings from TkEntry and TkListbox widgets.

Example

require 'tk'

root = TkRoot.new
root.title = "Window"
root.geometry("200x200")

combobox = TkCombobox.new(root)
combobox.values = [1, 2, 3, 4]
combobox.place('height' => 25, 
               'width'  => 100, 
               'x'   => 10, 
               'y'   => 10 )

Tk.mainloop

Output

This will produce the following result −

Ruby/Tk Combobox
ruby_tk_guide.htm
Advertisements