Using Wxpython Rich Text Control
I am using a rtf control to display text. I cannot understand the rtf control object structure. How do you get text into the rtf buffer? I have accessed the buffer and added an xml
Solution 1:
I have given this up as a bad job. I'm sure it's possible, but no one seems to be able to guide me
Instead I have implemented the functionality using
html.HtmlWindow
The revised code, which functions perfectly, is:
import wx
import wx.html as html
classMainFrame(wx.Frame):
"""Create MainFrame class."""def__init__(self):
"""Initialise the class."""
wx.Frame.__init__(self, None, -1, 'Demonstrate wxPython Html')
self.panel = MainPanel(self)
self.Centre()
self.html_display.SetPage(self.raw_html())
@staticmethoddefraw_html():
html = ('<p><font color="#4C4C4C", size=2>What do we want: ''<font color="#FF0000">all</font>''</p>')
return html
classMainPanel(wx.Panel):
"""Create a panel class to contain screen widgets."""def__init__(self, frame):
"""Initialise the class."""
wx.Panel.__init__(self, frame)
html_sizer = self._create_html_control(frame)
main_sizer = wx.BoxSizer(wx.HORIZONTAL)
main_sizer.Add(html_sizer, flag=wx.ALL, border=10)
self.SetSizerAndFit(main_sizer)
def_create_html_control(self, frame):
txt_style = wx.VSCROLL|wx.HSCROLL|wx.BORDER_SIMPLE
frame.html_display = html.HtmlWindow(self, -1,
size=(400, 200),
style=txt_style)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(frame.html_display)
return sizer
if __name__ == '__main__':
"""Run the application."""
screen_app = wx.App()
main_frame = MainFrame()
main_frame.Show(True)
screen_app.MainLoop()
A bit of work to convert the raw data, but not too much
Post a Comment for "Using Wxpython Rich Text Control"