Nictk 2.2.0
An easy to use pyton GUI
Listbox Class Reference

Listbox widget which can display a list of strings. More...

Inheritance diagram for Listbox:
Widget VerScroll Misc

Public Member Functions

def __init__ (self, parent, x, y, w, h, pad=0, items=[], command=None)
 The constructor. More...
 
def add (self, *items)
 Appends one or more items to the item list. More...
 
def config (self, cnf=None, **kw)
 Configures resources of the widget. More...
 
def delete (self, index1, index2=None)
 Deletes the items between index1 and index2 (included). More...
 
def get_config (self, key)
 Returns the value for the key resource. More...
 
def get_item (self, index)
 Returns the text of a menu item as a string. More...
 
def get_items (self)
 Returns a tuple of strings with all list items. More...
 
def get_select_mode (self)
 Gets the listbox select mode. More...
 
def index (self, ind)
 Returns the index of a menu item. More...
 
def insert (self, index, *items)
 Inserts one or more items at the given index. More...
 
def see (self, index)
 Scroll such that index is visible. More...
 
def select (self, item)
 Selects one or more items. More...
 
def selection_anchor (self, index)
 Set the fixed end of the selection. More...
 
def selection_clear (self, index1, index2=None)
 Clear the selection from index1 to index2. More...
 
def set_select_mode (self, mode)
 Sets the listbox select mode. 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 set_content (self, content)
 Sets the content 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 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 Member Functions inherited from VerScroll
def get_scrollbar ()
 Return the scrollbar widget. More...
 

Static Public Attributes

 get_selected = tk.Listbox.curselection
 Returns a tuple of int (the indexes of selected element). More...
 
- 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

Listbox widget which can display a list of strings.

It allows you to choose one or more of them and to associate a callback to the choice event. Moreover it adds and removes automatically a vertical scrollbar if the list becomes larger than the widget height.

Common options (see Widgets properties)

 bcolor, borderwidth, cursor, font, fcolor, hbcolor, hborder, hfcolor, 
 relief, sbcolor, sfcolor, state, takefocus

Less common options

 exportselection, selectborderwidth, selectmode,
 setgrid, xscrollcommand, yscrollcommand, listvariable

see anzeljg reference for the class tkinter.Listbox

Note
This widget doesn't have an associated tkinter.Variable object, because it has multiple selection modes, and some of them can return lists of strings (see selection_mode() and get_selection_mode()). If you want to know what is selected use the get_selected() method (which always returns a tuple, eventually empty).
See also
Listbox.py example file

Constructor & Destructor Documentation

◆ __init__()

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

The constructor.

You can specify here the initial item list of the listbox and a callback to associate to the choice of an item.

Parameters
parentthe widget parent
x,y,w,h,padsee Placing the widgets
itemsyou can specify here the list of items as strings
commandsee Events and callbacks

Reimplemented from VerScroll.

Member Function Documentation

◆ add()

def add (   self,
items 
)

Appends one or more items to the item list.

It is equivalent to insert(self, END, *items)

Parameters
*itemsone or more strings

◆ config()

def config (   self,
  cnf = None,
**  kw 
)

Configures resources of the widget.

We need to redefine this for this class. See Nictk.Widget.config().

Reimplemented from Misc.

◆ delete()

def delete (   self,
  index1,
  index2 = None 
)

Deletes the 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. see insert()
Note
be careful: if you specify two strings all items between them will be deleted

◆ get_config()

def get_config (   self,
  key 
)

Returns the value for the key resource.

We need to redefine this for this class. See Nictk.Widget.get_config().

Reimplemented from Misc.

◆ get_item()

def get_item (   self,
  index 
)

Returns the text of a menu item as a string.

Parameters
indexan int (starting from 0); if the index is greater than the 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 list items.

◆ get_select_mode()

def get_select_mode (   self)

Gets the listbox select mode.

See set_select_mode().

◆ index()

def index (   self,
  ind 
)

Returns the index of a menu item.

If the item is not in the mnenu returns None.

Parameters
inda string (the label of the menu item), or one of the constants "active", "anchor", "end" (or their aliases ACTIVE, ANCHOR, END)

◆ insert()

def insert (   self,
  index,
items 
)

Inserts one or more items at the given index.

Parameters
indexthe insert position; it can be
  • an int (beginning from 0, if the int is greater than the list size it becomes the end of the list)
  • a string already in the options list (items will be inserted BEFORE it)
  • one of the constants "active", "anchor", "end" (or their aliases ACTIVE, ANCHOR, END)
*itemsone or more strings (the item labels) to be inserted

◆ see()

def see (   self,
  index 
)

Scroll such that index is visible.

Parameters
indexsee insert()

◆ select()

def select (   self,
  item 
)

Selects one or more items.

Parameters
itemcan be
  • an int (the index of the selected element starting from 0)
  • a string already in the list
  • one of the constants "active", "anchor", "end" (or their aliases ACTIVE, ANCHOR, END)
  • a tuple of previous ones. In this case the items are selected only if the select mode is "multiple" or "extended"

◆ selection_anchor()

def selection_anchor (   self,
  index 
)

Set the fixed end of the selection.

Parameters
indexsee insert()

◆ selection_clear()

def selection_clear (   self,
  index1,
  index2 = None 
)

Clear the selection from index1 to index2.

See delete()

◆ set_select_mode()

def set_select_mode (   self,
  mode 
)

Sets the listbox select mode.

Parameters
modehere you can specify
  • "single": the user can select only one item at once, clicking on it in the listbox" + "browse": the user can select only one item at once, clicking on it or dragging with the mouse + "multiple": the user can select multiple items, clicking on them; clicking on a selected item unselects it"
  • "extended": the user can select multiple items, clicking, dragging the mouse and using the <CTRL> or <SHIFT> keys

Member Data Documentation

◆ get_selected

get_selected = tk.Listbox.curselection
static

Returns a tuple of int (the indexes of selected element).

Returns an empty tuple if no element is selected."""


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