Search code examples
python-3.xwxpythonwxwidgets

Display number in rectangle


Note that I am using Python3 and Phoenix.

I would like to display a number (double, but that does not matter now) formatted in some way (again, no matter what that way is) within a rectangle: almost a wx.StaticText but not editable by the user. This is to display some data coming from some hardware, such as a temperature.

Is there such a widget?

I tried with using the default wx.StaticText with a style but I must have done something wrong:

    hbox = wx.BoxSizer(wx.HORIZONTAL)

    title = wx.StaticText(parent, label=label)
    title.SetLabelMarkup("<b>{}</b>".format(label))
    hbox.Add(title, border=5)

    value = wx.StaticText(parent, label="3.141592", style=wx.BORDER_RAISED)
    value.SetWindowStyle(wx.BORDER_SIMPLE)
    hbox.Add(value, border=5)

    title = wx.StaticText(parent, label="\u2103")
    hbox.Add(title, border=5)

Shows this on Linux (Fedora 24, GTK):

Screenshot


Solution

  • Wouldn't using a wx.TextCtrl set to read only do the job?

    Temp = wx.TextCtrl(panel1, value="3.141592", style=wx.TE_READONLY)
    Temp.SetBackgroundColour('green')
    

    enter image description here