Take the 2-minute tour ×

When I use wx python to create a button with a file name as the button label, I lose the & character that is inside of the file names.

If a file were named: hello&goodbye.txt, the button would read: hellogoodbye.txt

I have no idea where the & character goes and would love a little help here.

share|improve this question
I'm guessing it's being interpreted as the accelerator key indicator. Try escaping it to && before you set the text. –  Cameron Jun 11 '12 at 16:49
Do you need an ampersand in a filename? –  eumiro Jun 11 '12 at 16:53
Yes, I am going to be using this button to open a file with that exact name when clicked. The ampersand is non-negotiable –  Mizmor Jun 11 '12 at 17:03

2 Answers 2

up vote 5 down vote accepted

The & character is a special symbol for those kinds of buttons. It defines what key you press to use a keyboard shortcut.

&x - [Alt]+[x] hotkey shortcut. You can escape it by using a second: && -> '&' char

share|improve this answer
I edited your answer to make it more clear. –  Daenyth Jun 11 '12 at 16:52
@Daenyth, thanks! –  astynax Jun 11 '12 at 16:54
@Daenyth That’s a nice edit but it was fundamental enough to actually merit an own answer. –  Konrad Rudolph Jun 11 '12 at 16:54
@KonradRudolph: Better one solid answer than a solid one and a duplicate that's less clear. I'm not really in it for the rep. –  Daenyth Jun 11 '12 at 16:56
The clarification did help me out. Thanks Daenyth. –  Mizmor Jun 11 '12 at 17:08

The ampersand seems to be some kind of token. Have a read here. It basically says this:

Found the answer: two ampersands.

share|improve this answer

Your Answer


