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框中的所有文本都變成灰色背景。