0

I am using wxPython and want my HtmlWindow to scroll down automatically after adding new content. I am using it as a log window inside my app. Unfortunately, I am struggling to get it working. Here is my sample with lacks the functionality:

import wx
import wx.html


class GUI(wx.Frame):

    def __init__(self, parent):
        super().__init__(parent)
        self.html = wx.html.HtmlWindow(self, -1, pos=(0, 0), size=(50, 50))
        msg = '<pre>FOO</pre>'
        for i in range(10):
            self.html.AppendToPage(msg)


if __name__ == '__main__':
    app = wx.App()
    frame = GUI(parent=None)
    frame.Show()
    app.MainLoop()

I want the scrollbar showing the stack of "Foos" to be at the bottom instead of staying on top so that the latest logging content is shown to the user.

Robert_Jordan
  • 256
  • 4
  • 13

1 Answers1

0

Arguably wx.html.HtmlWindow is the wrong tool to use.

You'd have to insert Anchors and then leap to each Anchor.

For a log, it's better to use a wx.TextCtrl e.g.

import wx
import time

class GUI(wx.Frame):

    def __init__(self, parent):
        super().__init__(parent)
        self.log = wx.TextCtrl(self, wx.ID_ANY, size=(600, 480),
                          style=wx.TE_MULTILINE| wx.TE_READONLY| wx.VSCROLL)
        # set initial position at the start
        self.log.SetInsertionPoint(0)
        self.Show()
        
        msg = 'FOO\n'
        for i in range(50):
            self.log.write(msg)
            wx.GetApp().Yield()
            time.sleep(0.5)

if __name__ == '__main__':
    app = wx.App()
    frame = GUI(parent=None)
    app.MainLoop()
Rolf of Saxony
  • 21,661
  • 5
  • 39
  • 60