0
我在我的代码中使用了wx.TextCtrl.SetStyle(),但它改变了所有文本的样式!wxPython SetStyle不工作
这里是我的代码:
# Get all the words in my TextCtrl
words = self.GetValue().split(" ")
# Find out what the farthest uneditable word is.
farthest_uneditable = (len(words) // length_constants["words_per_block"]) * length_constants["words_per_block"]
# Use this word knowledge to calculate the actual farthest uneditable character is
farthest_position = 0
for word in range(farthest_uneditable):
farthest_position += len(words[word]) + 1
# Make all the uneditable text (everything from the beginning to farthest_uneditable) have a grey background
self.SetStyle(0, farthest_position, wx.TextAttr(wx.NullColour, (84, 84, 84)))
我已经测试此代码,并确保我farthest_position是不是在我的TextCtrl结束(它已经在每一次的预期位置)。出于某种原因,我的TextCtrl框中的所有文本都变成灰色背景。