0
이것이 내가 원하는 것입니다 : 사용자가 원하는 색상을 기준으로 버튼을 선택합니다. 그런 다음 해당 색상으로 강조 표시 할 단어를 클릭합니다.
다음과 같은 현상이 발생합니다. 사용자가 이전에 사용한 색상을 원한다고해도 사용자가 색상을 선택하고 이전 단어가 모두 색상으로 변경됩니다.
아래는 강조 표시된 코드입니다. 변수 검색Python tkinter- 여러 색상 강조하기
def _on_click(self, event):
if "highlight" in tags:
#Unhighlights
ArticleTextBox.tag_remove("highlight", "insert wordstart", "insert wordend")
wordclicked=ArticleTextBox.get("insert wordstart", "insert wordend")
SearchLEN=len(Search)
for x in range(0,SearchLEN):
if Search[x]==wordclicked:
#global Search # Needed to modify global copy of globvar
Search.remove(wordclicked)
else:
#highlights
ArticleTextBox.tag_add("highlight", "insert wordstart", "insert wordend")
wordclicked=ArticleTextBox.get("insert wordstart", "insert wordend")
#global Search # Needed to modify global copy of globvar
Search.append(wordclicked)
#print(Search)
의 텍스트를 가지고 있으며,이
#Colour picker
def sel(self):
selection = "You selected the option " + str(var.get())
colournumber=(var.get())
if colournumber==2:
ArticleTextBox.tag_config('highlight', background='yellow', foreground='black')
elif colournumber==3:
#print("Sorry this is not working at the moment- Please go back to name selection before you click the button")
ArticleTextBox.tag_config('highlight', background='blue', foreground='black')
else:
ArticleTextBox.tag_config('highlight', background='yellow', foreground='black')
은 언제나, 어떤 질문을 기꺼이 받아 대답 할 색상을 선택하는 코드입니다. 해피 크리스마스
대신에 하나의 태그'highlight'는 색상 이름'tag_add ('highlight_red ", ...)로 다른 태그를 사용하고 시작시 한 번만 모든 태그에 색상을 지정해야합니다. – furas