Message61042
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 ''
---
|
|
Date |
User |
Action |
Args |
2008-01-20 09:59:07 | admin | link | issue1602742 messages |
2008-01-20 09:59:07 | admin | create | |
|