2017-12-02 26 views
-1

메모장을 만들고 글꼴 도구를 만들었지 만 선택한 조각이나 현재있는 부분이 아닌 모든 텍스트의 글꼴이 바뀝니다텍스트 조각의 글꼴 소유권 변경

모든 도구에 대한 코드는 다음과 같습니다

def ng(): 
    global fn #the font 
    global b #Bold variable 

    b=not b 
    if b==True: 
     fn.configure(weight="bold") 
    if b==False: 
     fn.configure(weight="normal") 

    scroll.config(font=fn) 

나는이 작업을 수행하는 방법?

+0

askng 전에 연구를 해본 적이 있습니까? 이 사이트에는 여러 가지 질문이 있습니다. –

+0

예, 이전에 많이 연구했습니다. – KaiXtr

+0

다르게 보이게하려는 텍스트 조각에 태그를 지정한 다음 tag_config 메서드를 사용하여 태그가있는 텍스트의 속성을 변경해야합니다. 이것은 tkinter 기반 IDLE 구문 색상이 파이썬 코드 인 방법입니다. 'http : // infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html'에있는 텍스트 위젯 문서를 읽으십시오. 또한 '텍스트 태그'또는 그와 비슷한 것을 찾기 위해 'tkinter'태그가 지정된 질문을 검색해보십시오. –

답변

1

글꼴 대신 전경색을 사용하는 것이 간단한 예이며 새 글꼴을 만드는 것은 별개의 문제입니다.

import tkinter as tk 
root = tk.Tk() 
text = tk.Text(root) 
text.pack() 
text.tag_config('RED', foreground='red') 
text.tag_config('BLUE', foreground='blue') 
text.insert('insert', 'Some tk colors are ') 
text.insert('insert', 'red', 'RED') 
text.insert('insert', ' and ') 
text.insert('insert', 'blue', 'BLUE') 
text.insert('insert', '.') 
root.update() 

삽입 된 텍스트 뒤에 태그를 추가하고 태그 구성을 사용한 후이를 변경할 수 있습니다.