Can't see line numbers in StyledTextCtrl()

I’m trying to add line numbers to my StyledTextCtrl().

When I run my small app, there are no line numbers in the left margin at all. Am I missing a step? Do I have to do something else?

My test appt:

import wx
import wx.stc

class testApp(wx.Frame):
    def __init__(self, *args, **kw):
        # ensure the parent's __init__ is called
        super(testApp, self).__init__(*args, **kw)

        self.editor = wx.stc.StyledTextCtrl(self, style=wx.TE_MULTILINE)
        self.editor.SetScrollWidth(wx.stc.STC_CACHE_CARET)
        #self.stc.EditToggleOvertype()
        self.editor.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "size:10,face:Courier New, fore: #dddddd, back: #000000")
        self.editor.SetMarginWidth(1, 20)
        self.editor.SetMarginType(0, wx.stc.STC_MARGIN_NUMBER)

        self.CreateStatusBar()
        self.SetStatusText("Welcome to testApp")

if __name__ == '__main__':
    app = wx.App()
    win = testApp(None, title='testApp')
    win.SetPosition(wx.Point(400, 400))
    win.Show()

    app.MainLoop()

Try using:

self.editor.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
self.editor.SetMarginMask(1, 0)
self.editor.SetMarginWidth(1, 20)

instead of:

self.editor.SetMarginWidth(1, 20)
self.editor.SetMarginType(0, wx.stc.STC_MARGIN_NUMBER)
1 Like

Wow that’s perfect!!! Thank you so much!!!