wxPython, Set value of StaticText() wxPython, Set value of StaticText() python python

wxPython, Set value of StaticText()


If you are using a wx.StaticText() you can just:

def __init__(self, parent, *args, **kwargs): #frame constructor, etc.    self.some_text = wx.StaticText(panel, wx.ID_ANY, label="Awaiting MySQL Data", style=wx.ALIGN_CENTER)def someFunction(self):    mysql_data = databasemodel.returnData() #query your database to return a string    self.some_text.SetLabel(mysql_data)

As litb mentioned, the wxWidgets docs are often much easier to use than the wxPython docs. In order to see that the SetLabel() function can be applied to a wx.StaticText instance, you have to travel up the namespace hierarchy in the wxPython docs to the wxWindow superclass, from which wx.StaticText is subclassed. There are a few things different in wxPython from wxWidgets, and it can be challenging to find out what they are. Fortunately, a lot of the time, the differences are convenience functions that have been added to wxPython and are not found in wxWidgets.


wx.TextCtrl has a style called wx.TE_READONLY . Use that to make it read-only.

As a sidenode, you can use the C++ wxWidgets Manual for wxPython aswell. Where special handling for wxPython or other ports is required, the manual often points out the difference.