コードで 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 ボックス内のすべてのテキストの背景が灰色になっています。