Nictk 2.2.0
An easy to use pyton GUI
Combobox Class Reference

Combobox which allows the user to select a value from a menu. More...

Inheritance diagram for Combobox:
Widget Misc

Public Member Functions

def __init__ (self, parent, x, y, w, h, pad=0, items=[], variable=None, command=None)
 The constructor. More...
 
def add (self, *items)
 Appends one or more items to the list of options. More...
 
def clear (self)
 Deletes all menu items. More...
 
def config_item (self, index, cnf=None, **kw)
 Configures a menu item. More...
 
def delete (self, index1, index2=None)
 Deletes menu items between index1 and index2 (included). More...
 
def get_config_item (self, index, option)
 Returns the resource value of a menu item. More...
 
def get_item (self, index)
 Returns the label of a menu item. More...
 
def get_items (self)
 Returns a tuple of strings with all menu labels. More...
 
def get_menu (self)
 Returns the internal Menu object. More...
 
def index (self, index)
 Returns the index of a menu item. More...
 
def insert (self, index, *items)
 Inserts one or more items to the list of options at a given position. More...
 
def invoke (self, index)
 Invokes the given menu item and executes the associated command. More...
 
def set_content (self, index, invoke=True)
 Selects a menu item. More...
 
- Public Member Functions inherited from Widget
def activate (self)
 Sets the state of the widget to NORMAL. More...
 
def deactivate (self)
 Sets the state of the widget to DISABLED. More...
 
def destroy (self)
 Overrides the BaseWidget method, unmapping the widget if its parent is a _embedVerFrame. More...
 
def enabled (self)
 Returns True if the widget is enabled. More...
 
def get_content (self)
 Returns the content of the widget as a string. More...
 
def hide (self)
 Hides the widget. More...
 
def init_content (self, content)
 Sets the content type for the widget. More...
 
def resize (self, x=None, y=None, w=None, h=None, pad=None)
 Changes the dimensions of the widget. More...
 
def show (self)
 Shows a previously hidden widget. More...
 
def visible (self)
 Returns True if the widget is visible. More...
 
- Public Member Functions inherited from Misc
def bind (self, sequence=None, func=None, add=None)
 Redefines the tk.Misc.bind() method. More...
 
def config (self, cnf=None, **kw)
 Configures resources of a widget. More...
 
def get_config (self, key)
 Returns the value for the key resource. More...
 
def get_winfo (self, key)
 Returns the widget info for the item key. More...
 
def has_option (self, opt=None)
 Returns True if the widget admits the given option. More...
 
def parent (self)
 Returns the widget parent. More...
 
def toplevel (self)
 Returns the widget toplevel container (a Window or Main). More...
 
def unbind (self, sequence, funcid=None)
 Redefines the tk.Misc.unbind() method. More...
 
def winfo_bh (self)
 Returns the height of the widget bounding box. More...
 
def winfo_bpad (self)
 Returns the list of the four pad amounts (E-N-W-S) of the widget with respect to its bounding box. More...
 
def winfo_bw (self)
 Returns the width of the widget bounding box. More...
 
def winfo_bx (self)
 Returns the x coordinate of the widget bounding box topleft corner. More...
 
def winfo_by (self)
 Returns the y coordinate of the widget bounding box topleft corner. More...
 
def winfo_height (self)
 Returns the widget height. More...
 
def winfo_width (self)
 Returns the widget width. More...
 
def winfo_x (self)
 Returns the x coordinate of the topleft corner of the widget with respect to the parent. More...
 
def winfo_y (self)
 Returns the y coordinate of the topleft corner of the widget with respect to the parent. More...
 

Public Attributes

 callback
 
 menuname
 
 widgetName
 

Additional Inherited Members

- Static Public Attributes inherited from Misc
def winfo_h = winfo_height
 Alias for winfo_height() More...
 
def winfo_w = winfo_width
 Alias for winfo_width() More...
 

Detailed Description

Combobox which allows the user to select a value from a menu.

It is the equivalent (renamed) of the OptionMenu class in tkinter. You can get the selected item with the get_content() method, it will return an empty string if no selection is done.

Common options (see Widgets properties)

abcolor, afcolor, bcolor, borderwidth, cursor, dfcolor, font,
fcolor, relief, scolor, state, takefocus.

Less common options

activeborderwidth, postcommand, tearoff, tearoffcommand, title, type.

see anzeljg reference for the class tkinter.OptionMenu

See also
Combobox.py Menu.py example files

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  parent,
  x,
  y,
  w,
  h,
  pad = 0,
  items = [],
  variable = None,
  command = None 
)

The constructor.

You can specify here the label of the button, a Variable object which will be updated when the state change and a callback to associate to state change.

Parameters
parentthe widget parent
x,y,w,h,padsee Placing the widgets
itemsa list of strings for the menu options
variablea StringVar which is automatically updated at every menu choice; if you leave None a StringVar is automatically created. A <<ChangedVar>> event is generated when its value changes
commandsee Events and callbacks

Reimplemented from Widget.

Member Function Documentation

◆ add()

def add (   self,
items 
)

Appends one or more items to the list of options.

Parameters
*itemsone or more strings (the item labels) to be appended (or list/tuples containing strings)

◆ clear()

def clear (   self)

Deletes all menu items.

◆ config_item()

def config_item (   self,
  index,
  cnf = None,
**  kw 
)

Configures a menu item.

It is aliased by entry_config().

Parameters
indexyou can specify an int (the menu item index) or a string (the label of the item)
cnf,**kwthe options

◆ delete()

def delete (   self,
  index1,
  index2 = None 
)

Deletes menu items between index1 and index2 (included).

Parameters
index1,index2the first and last items to be deleted; if you leave index2 = None only index1 will be deleted. These can be integers or strings already in the options list. If the current selected item gets cancelled it resets the selection.
Note
be careful: if you specify two strings ALL items between them will be deleted

◆ get_config_item()

def get_config_item (   self,
  index,
  option 
)

Returns the resource value of a menu item.

It is aliased by entry_get_config().

Parameters
indexyou can specify an int (the menu item index) or a string (the label of the item)
optionthe option we want to know (as a string)

◆ get_item()

def get_item (   self,
  index 
)

Returns the label of a menu item.

Parameters
indexan int (starting from 0); if the index is greater than the menu length the last element is returned; if the menu is empty an empty string is returned.

◆ get_items()

def get_items (   self)

Returns a tuple of strings with all menu labels.

◆ get_menu()

def get_menu (   self)

Returns the internal Menu object.

You can then apply to it the Menu methods.

◆ index()

def index (   self,
  index 
)

Returns the index of a menu item.

If the item is not in the menu it gives a TclError.

Parameters
indexa string (the label of the menu item)

◆ insert()

def insert (   self,
  index,
items 
)

Inserts one or more items to the list of options at a given position.

Parameters
indexthe insert position; it can be an int (beginning from 0) or a string already in the options list (items will be inserted BEFORE it)
*itemsone or more strings (the item labels) to be inserted (or lists/tuples containing strings)

◆ invoke()

def invoke (   self,
  index 
)

Invokes the given menu item and executes the associated command.

Parameters
indexyou can specify an int (the menu item index) or a string (the label of the item).

◆ set_content()

def set_content (   self,
  index,
  invoke = True 
)

Selects a menu item.

Parameters
indexhere you can specify:
  • an int (starting from 0): the corresponding item will become the selected one; if the index is greater than the menu length the last element is selected
  • an empty string: this deselects all items
  • one of the menu items strings: this will become the selected item; if the string is not in the menu the selection remains unchanged
invokeif True the associated callback will be executed

Reimplemented from Widget.


The documentation for this class was generated from the following file: