From a0adb92b23c5b022d0049e156d0b43b94058b056 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sat, 1 Sep 2001 18:29:55 +0000 Subject: [PATCH] Add Listbox.itemconfig[ure] call. (A "recent" addition to Tk -- 8.0 doesn't have it.) This is from SF bug #457487 by anonymous. --- Lib/lib-tk/Tkinter.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py index 746adf1644f..a5a18c44543 100644 --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -3,16 +3,16 @@ Tkinter provides classes which allow the display, positioning and control of widgets. Toplevel widgets are Tk and Toplevel. Other widgets are Frame, Label, Entry, Text, Canvas, Button, Radiobutton, -Checkbutton, Scale, Listbox, Scrollbar, OptionMenu. Properties of the widgets are -specified with keyword arguments. Keyword arguments have the same -name as the corresponding resource under Tk. +Checkbutton, Scale, Listbox, Scrollbar, OptionMenu. Properties of the +widgets are specified with keyword arguments. Keyword arguments have +the same name as the corresponding resource under Tk. Widgets are positioned with one of the geometry managers Place, Pack or Grid. These managers can be called with methods place, pack, grid available in every Widget. -Actions are bound to events by resources (e.g. keyword argument command) or -with the method bind. +Actions are bound to events by resources (e.g. keyword argument +command) or with the method bind. Example (Hello, World): import Tkinter @@ -2363,6 +2363,27 @@ class Listbox(Widget): def yview_scroll(self, number, what): """Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT).""" self.tk.call(self._w, 'yview', 'scroll', number, what) + def itemconfigure(self, index, cnf=None, **kw): + """Configure resources of an item. + + The values for resources are specified as keyword arguments. + To get an overview about the allowed keyword arguments + call the method without arguments. + Valid resource names: background, bg, foreground, fg, + selectbackground, selectforeground.""" + if cnf is None and not kw: + cnf = {} + for x in self.tk.split( + self.tk.call(self._w, 'itemconfigure', index)): + cnf[x[0][1:]] = (x[0][1:],) + x[1:] + return cnf + if type(cnf) == StringType and not kw: + x = self.tk.split(self.tk.call( + self._w, 'itemconfigure', index, '-'+cnf)) + return (x[0][1:],) + x[1:] + self.tk.call((self._w, 'itemconfigure', index) + + self._options(cnf, kw)) + itemconfig = itemconfigure class Menu(Widget): """Menu widget which allows to display menu bars, pull-down menus and pop-up menus."""