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.

classification
Title: ttk.Combobox['values'] String Conversion to Tcl
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder: ttk.Treeview "unmatched open brace in list"
View: 15861
Assigned To: Nosy List: PendulumDreams, claytondarwin, gpolo, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2011-02-22 17:05 by claytondarwin, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tcl_string_test.py claytondarwin, 2011-02-22 17:05 Illustrates ttk.Combobox['values'] string error.
patch11290.diff gpolo, 2011-03-06 15:39
tested_patch.png PendulumDreams, 2012-12-11 20:31 Image of 2 combo boxes. Top with no patch, bottom with patch applied.
Messages (9)
msg129097 - (view) Author: Clayton Darwin (claytondarwin) Date: 2011-02-22 17:05
In working with the ttk.Combobox (Windows XP, Python 3.1), I have found that setting the values for the popdown using ttk.Combobox['values'] has an problem converting the string to the proper Tcl value when (and this is the only instance I have found) there is a backslash in the string but no spaces.  In this case, the string will translate if it is enclosed in curly brackets '{'+mystring+'}', which I believe is the Tcl syntax to not make substitutions.

I have attached a short script that illustrates this issue.

Clayton
msg129417 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-02-25 20:24
With 3.2, (Winxp) I get combobox with first line,
input as
r'C:\Python31\Lib\tkinter\test\test_ttk',
displayed as
"C:Python31Lib	kinter	est	est_ttk"
Something either deleted \ or converted \t to tab.
Indeed, adding a space to the end of the string or enclosing as you specify inhibits deletion/conversion, so this seems like an error.

With imports fixed
from Tkinter import *
import ttk
the file runs fine in 2.7, so this seems 3.x specific problem.
msg129422 - (view) Author: Clayton Darwin (claytondarwin) Date: 2011-02-25 20:39
This is a simple work around.  

def fix_tcl_error(s):

    if '\\' in s and not ' ' in s:
        s = '{'+s+'}'

    return s

You can get the text from the Combobox with no issues.  The error is in posting it to the Combobox when you have backslashes and no spaces (I think).  I have just been running everything through this def before adding it.  It has worked with no problems so far using Windows paths and grep-type search strings.

CD
msg130174 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2011-03-06 15:39
Does the attached patch work for you ?
msg177349 - (view) Author: Jayden Kneller (PendulumDreams) Date: 2012-12-11 20:31
I also ran into this issue in python 3.3 64bit on windows 7.  I was adding paths into a combo box and was escaping all \'s myself.  When I created a folder with a space I noticed the paths with the space had double the \'s I wanted.

I removed my escaping and tested the patch and the attached image shows that it works.  The top of the image was before, the bottom of the image was after.
msg177351 - (view) Author: Jayden Kneller (PendulumDreams) Date: 2012-12-11 20:33
I should also add that I yellow highlighed where the space is in the image I attached so it easier to see.
msg177353 - (view) Author: Jayden Kneller (PendulumDreams) Date: 2012-12-11 20:36
On a side note:

If you pass raw string literals into the combo box as values this issue doesn't happen.
msg177355 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-11 20:49
Issue15861 has a more general patch which fixes also this issue.
msg180030 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-15 16:09
Fixed in issue15861. Thank you for report, Clayton Darwin.
History
Date User Action Args
2022-04-11 14:57:13adminsetgithub: 55499
2013-01-15 16:09:07serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg180030

stage: resolved
2012-12-12 09:46:01serhiy.storchakasetsuperseder: ttk.Treeview "unmatched open brace in list"
versions: + Python 2.7, Python 3.2, Python 3.4
2012-12-11 20:49:27serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg177355
2012-12-11 20:36:24PendulumDreamssetmessages: + msg177353
2012-12-11 20:33:14PendulumDreamssetmessages: + msg177351
2012-12-11 20:31:17PendulumDreamssetfiles: + tested_patch.png
versions: - Python 3.1, Python 3.2
nosy: + PendulumDreams

messages: + msg177349
2011-03-06 15:39:22gpolosetfiles: + patch11290.diff

messages: + msg130174
keywords: + patch
nosy: terry.reedy, gpolo, claytondarwin
2011-02-25 20:39:52claytondarwinsetnosy: terry.reedy, gpolo, claytondarwin
messages: + msg129422
2011-02-25 20:24:55terry.reedysetnosy: + gpolo, terry.reedy

messages: + msg129417
versions: + Python 3.2, Python 3.3
2011-02-22 17:05:20claytondarwincreate