简体   繁体   中英

wxPython RichTextCtrl.SetStyle([…]) Issue

I want to change the font of a RichTextControl in wxPython but I've encountered an issue that I can not figure out. Here is the relevant code:

import wx
import wx.richtext as rt
#....
codebox = rt.RichTextCtrl(self)
f = wx.Font(10, wx.TELETYPE, wx.NORMAL, wx.NORMAL)
s = wx.TextAttr(font = f)
codebox.SetStyle((0,0), s)

The last line is what throws an error. Specifically:

TypeError: in method 'RichTextCtrl_GetStyle', 
expected argument 3 of type 'wxTextAttrEx &'

I based my code on stuff I found online, however I immediately recognized that my version of wxPython was different because the tuple I supplied as a range in SetStyle() was instead supplied as two different arguments, however when I imitated that setup the interpreter threw me an error and asked me to use a tuple.

Does anyone know where I'm going wrong? Or, of course, a workaround? Thanks.

s should be of type wx.TextAttrEx, not wx.TextAttr like you have done.

SetStyle(self, range, style)

Set the style for the text in range to style

 Parameters: range (type=RichTextRange) style (type=TextAttrEx) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM