pythonwxpythontextctrlwxtextctrl

Difference between wx.TextCtrl .write / .WriteText / .AppendText


I am new to Python and so i am new to wxPython as well. I was just wondering if there is any difference between these wx.TextCtrl functions. This mini code shows three times the same output. If there is no difference, is there a historic reason for these functions?

import wx

class testUI(wx.Panel):
    textCtrl = ''

    def __init__(self, parent, name):
        super(testUI, self).__init__(parent, name=name)
        self.buildUI()
        self.Show(True)
        self.textCtrl.write('bli\n')
        self.textCtrl.WriteText('bla\n')
        self.textCtrl.AppendText('blub\n')

    def buildUI(self):
        self.textCtrl = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY)
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.textCtrl, proportion=1, flag=wx.EXPAND)

def main():
    app = wx.App(False)
    root = wx.Frame(parent=None, title='testUI')
    testUI(parent=root, name='testUI')
    root.Show(True)
    app.MainLoop()

# Standard boilerplate to call the main() function.
if __name__ == '__main__':
    main()

thanks :)


Solution

  • The 3 methods appear to be functionally the same. However, I would argue that you would use AppendText for adding additional text to a text control to make what you're doing very clear in the code itself. Most of the time, you will normally use SetValue. I have used WriteText when redirecting stdout, but that's it. You can read about that use case here: