Bugs item #1602742, was opened at 2006-11-25 16:27 Message generated for change (Comment added) made by mkiever 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 '' --- ---------------------------------------------------------------------- Comment By: Matthias Kievernagel (mkiever) Date: 2007-01-19 18:35 Message: Logged In: YES user_id=1477880 Originator: NO There is a simple workaround: use itemcget. The error applies to other options as well: dash, activedash, disableddash, tags, arrowshape, font These options also may contain a space in their value. I collected this information from 'man n Canvas' from Tk 8.4.6 I hope I didn't miss any. BTW the itemconfigure document string is broken. Greetings, Matthias Kievernagel ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1602742&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com