New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
itemconfigure returns incorrect text property of text items #44274
Comments
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 This toy prints: sample text with spaces The returned value is not a string -- Tk returns the same *** Tkinter.py.old 2006-11-20 16:48:27.000000000 +0100 *** 1122,1129 **** 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 --- 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 '' |
There is a simple workaround: use itemcget. The error applies to other options as well: BTW the itemconfigure document string is broken. Greetings, |
I no longer know what I meant with "document string is The problem is still present in trunk. So I think it's a more general bug related to tcl string Matthias. |
The problem is actually on Tkinter side, not really tcl/tk fault here. To try this yourself, just change text to: I can't look at Tkinter source right now to propose a correct solution, |
Uhm, now I see.. Tkinter already formats it correctly, and you shouldn't canvas .c You would get something like this: -text {} {} {} {a b} While .c itemcget 1 -text Will return the same as Python: "a b" Now what remains is to see how useful is to use itemconfigure for this, |
The patch for bpo-19020 fixes this issue. |
Hi, the status of this issue is pending but it seems to be already Thansk in advance! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: