homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author wmula
Recipients
Date 2006年11月25日.16:27:13
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
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 ''
---
History
Date User Action Args
2008年01月20日 09:59:07adminlinkissue1602742 messages
2008年01月20日 09:59:07admincreate

AltStyle によって変換されたページ (->オリジナル) /