[英]wxPython: Changing the color scheme of a wx.stc.StyledTextCtrl
[英]wxPython StyledTextCtrl Set (Partial) Text Color
如何在StyledTextCtrl中設置文本顏色,但只能輸入一些單詞? 我的意思是說我有
露西是藍色的
我只希望單詞“ Blue”被塗成藍色
有關StyledTextCtrl的信息,請參見wxPython演示。 它顯示了如何執行此確切操作。 我認為您正在尋找的東西是這樣的:
ed.StartStyling(190, 0xff)
ed.SetStyling(20, 2)
190是第190個字符,您可以為接下來的20個字符設置樣式。
要更改線條的樣式,您必須獲取第一個字節和結尾字節的位置。 然后,您可以定義一個樣式(StyleSetSpec),該樣式從第一個字節開始(StartStyling),並應用於整行(SetStyling)。 您必須在末尾字節重新應用默認樣式(0)。 這是我的代碼:
# Move to line
self.editname.GotoLine(line-1)
# Get position
pos = self.editname.GetCurrentPos()
# Define style 4
self.editname.StyleSetSpec(4, "back:#ff0000")
# Starts style at position pos
self.editname.StartStyling(pos, 0xffff)
# Until posend position, apply style 4
self.editname.SetStyling(posend-pos, 4)
# Restore style 0 after the ending byte of the line
self.editname.SetStyling(posend, 0)
在text_area是StyledCtrlText的情況下使用此選項
self.text_area.StyleSetSpec(stc.STC_P_DEFAULT,"fore:#FF0000")
接下來將要更改顏色的文本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.