我在我的代码中使用 wx.TextCtrl.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 框中的所有文本都变成了灰色背景。