How can I see the '&' character in a label?

I can see ‘&’ in a wx.Frame Title or wx.TextCtrl Value,
but in a wx.Button Label or wx.CheckBox Label or wx.StaticText Label I can’t see anything.

On Window 10, 11
Python: 3.10 3.11 3.12
wx: 4.2.1a1

Do you have an idea for solving this problem?

Here’s a little demonstration code

import wx

class MainFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        wx.Frame.__init__(self, *args, **kwds)
        self.panel = wx.Panel(self)
        wx.TextCtrl(self.panel, value='Value -&-\x26-  $£§µùçàèé@',
                    pos=wx.Point(10, 10), size=wx.Size(220, 25))

        wx.StaticText(self.panel, label='Label -&-\x26-  $£§µùçàèé@',
                      pos=wx.Point(10, 40), size=wx.Size(220, 25))

        wx.CheckBox(self.panel, label='Label -&-\x26-  $£§µùçàèé@',
                    pos=wx.Point(10, 70), size=wx.Size(220, 25))
                    
        wx.Button(self.panel, label= 'Label -&-\x26- ',
                 pos=wx.Point(80, 100), size=wx.Size(80, 25), style=0)

app = wx.App()
main_frame = MainFrame(None, wx.ID_ANY, "Title -&-\x26-", size=(250, 200))
app.SetTopWindow(main_frame)
main_frame.Show()
app.MainLoop()

Try using double ampersand characters ‘&&’ to get one ampersand character to appear in the label of a Button, CheckBox or StaticText.

Edit: see the docs for the base class wx.Control (wx.Control — wxPython Phoenix 4.2.1 documentation)

It states:

All “&” characters in the label are special and indicate that the following character is a mnemonic for this control and can be used to activate it from the keyboard (typically by using Alt key in combination with it). To insert a literal ampersand character, you need to float it, i.e. use “&&”. If this behaviour is undesirable, use SetLabelText instead.

1 Like

As @RichardT points out the double ampersand is the key and that is especially true in Menu’s, which I always forget first time round. :grimacing:

Thank you
I hadn’t looked in the right place in the doc !