]> granicus.if.org Git - python/commitdiff
Patch #426880: Implement Listbox itemcget and itemconfigure.
authorMartin v. Löwis <martin@v.loewis.de>
Mon, 1 Oct 2001 10:09:31 +0000 (10:09 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Mon, 1 Oct 2001 10:09:31 +0000 (10:09 +0000)
Lib/lib-tk/Tkinter.py
Misc/NEWS

index 2b04ee0fbb292ceba77faec76ee2d2489b9ea937..e72dbe5e3db5a170bd073e2a8f0bb5b910cff549 100644 (file)
@@ -2299,6 +2299,31 @@ class Listbox(Widget):
         i = self.tk.call(self._w, 'index', index)
         if i == 'none': return None
         return getint(i)
+    def itemcget(self, index, option):
+        """Return the resource value for an ITEM and an OPTION."""
+        return self.tk.call(
+            (self._w, 'itemcget') + (index, '-'+option))
+    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, foreground,
+        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
     def insert(self, index, *elements):
         """Insert ELEMENTS at INDEX."""
         self.tk.call((self._w, 'insert', index) + elements)
index b7ccc862ca2b37550f11e3f7758ba3ccf766ffa0..d4daf27dfa3ed47bea3ec9d6bc961d2ee5384d71 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,8 @@ Library
 - quopri's encode and decode methods take an optional header parameter,
   which indicates whether output is intended for the header 'Q' encoding.
 
+- Tkinter.Listbox now exposes itemcget and itemconfigure.
+
 Tools
 
 Build