[ python-Bugs-1602742 ] itemconfigure returns incorrect text property of text items

SourceForge.net noreply at sourceforge.net
Sat Nov 25 17:27:13 CET 2006


Bugs item #1602742, was opened at 2006-11-25 17:27
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1602742&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Tkinter
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Wojciech Mula (wmula)
Assigned to: Martin v. Löwis (loewis)
Summary: itemconfigure returns incorrect text property of text items

Initial Comment:
Tkinter: canvas itemconfigure bug

Consider following code:

-- tkbug.py ---
from Tkinter import *
root   = Tk()
canvas = Canvas(root)
text   = "sample text with spaces"
id     = canvas.create_text(0, 0, text=text)

text2  = canvas.itemconfigure(id)['text'][-1]

print text
print text2
--- eof ---

This toy prints:

sample text with spaces
('sample', 'text', 'with', 'spaces')

The returned value is not a string -- Tk returns the same
string as passed on creating item, but Tkinter split it.
To fix this problem, internal method '_configure' have
to be changed a bit:

*** Tkinter.py.old	2006-11-20 16:48:27.000000000 +0100
--- Tkinter.py	2006-11-20 17:00:13.000000000 +0100
***************
*** 1122,1129 ****
              cnf = _cnfmerge(cnf)
          if cnf is None:
              cnf = {}
!             for x in self.tk.split(
                      self.tk.call(_flatten((self._w, cmd)))):
                  cnf[x[0][1:]] = (x[0][1:],) + x[1:]
              return cnf
          if type(cnf) is StringType:
--- 1122,1134 ----
              cnf = _cnfmerge(cnf)
          if cnf is None:
              cnf = {}
!             for x in self.tk.splitlist(
                      self.tk.call(_flatten((self._w, cmd)))):
+                 if type(x) is StringType:
+                     if x.startswith('-text '):
+                         x = self.tk.splitlist(x)
+                     else:
+                         x = self.tk.split(x)
                  cnf[x[0][1:]] = (x[0][1:],) + x[1:]
              return cnf
          if type(cnf) is StringType:


Maybe better/faster way is to provide Canvas method, that
return a 'text' property for text items:

---
def get_text(self, text_id):
	try:
		r = self.tk.call(self._w, 'itemconfigure', text_id, '-text')
		return self.tk.splitlist(r)[-1]
	except TclError:
		return ''
---


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1602742&group_id=5470


More information about the Python-bugs-list mailing list