随着SetStyle
您将属性应用于尚未编写的文本位置。
有一个选项允许您为整个文档或从现在开始设置属性 SetBasicStyle
。SetDefaultStyle
这是一个工作示例。
import wx
import wx.richtext as rt
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='Test RichText Superscript')
self.panel = wx.Panel(self)
self.rtc1 = rt.RichTextCtrl(self.panel,pos=(10,10),size=(350,90),style=wx.VSCROLL|wx.HSCROLL|wx.NO_BORDER|wx.FONTFAMILY_DEFAULT|wx.TEXT_ATTR_FONT_FACE)
self.rtc2 = rt.RichTextCtrl(self.panel,pos=(10,110),size=(350,90),style=wx.VSCROLL|wx.HSCROLL|wx.NO_BORDER|wx.FONTFAMILY_DEFAULT|wx.TEXT_ATTR_FONT_FACE)
self.Show()
attr_super = wx.richtext.RichTextAttr()
attr_super.SetTextEffects(wx.TEXT_ATTR_EFFECT_SUPERSCRIPT)
attr_super.SetFlags(wx.TEXT_ATTR_EFFECTS)
attr_super.SetTextEffectFlags(wx.TEXT_ATTR_EFFECT_SUPERSCRIPT)
self.rtc1.WriteText("Is this super?")
self.rtc1.SetStyle (7, 13, attr_super)
attr_sub = wx.richtext.RichTextAttr()
attr_sub.SetTextEffects(wx.TEXT_ATTR_EFFECT_SUBSCRIPT)
attr_sub.SetFlags(wx.TEXT_ATTR_EFFECTS)
attr_sub.SetTextEffectFlags(wx.TEXT_ATTR_EFFECT_SUBSCRIPT)
self.rtc1.AppendText ("\nIs this sub?")
self.rtc1.SetStyle (23, 26, attr_sub)
self.rtc1.AppendText ("\nIs this normal?")
self.rtc2.WriteText("Is this super?")
self.rtc2.SetDefaultStyle(attr_super)
self.rtc2.WriteText("\nIs this super?")
if __name__ == '__main__':
app = wx.App()
frame = MainFrame()
app.MainLoop()