250x250
250x250
  • 분류 전체보기 (48)
    • Save Your TIME (1)
      • WORK SMART - RPA (0)
      • 비 전공 직장인의 업무 자동화 고군분투기 (1)
    • Make a lot of MONEY (0)
      • 부동산 (0)
    • PYTHON (45)
      • BASIC (3)
      • pandas (3)
      • tkinter (8)
      • LIBRARY | ETC (1)
      • Tips (19)
      • Error Solutions (11)
    • EXCEL (0)
      • BASIC (0)
      • TIP (0)
    • Life & Education (2)
      • 초등 수학 (2)
      • English (0)
    • TISTORY (0)
      • ABOUT BLOG (0)
      • TIP (0)
    • Reference (0)
hELLO · Designed By 정상우.
Creatio ex nihilo

Py Life

Cannot clear output text: tkinter.TclError: bad text index "0"
PYTHON/Error Solutions

Cannot clear output text: tkinter.TclError: bad text index "0"

2022. 6. 10. 20:21
728x90
반응형
"Life is too short, You need python"

 

Entry Widget에서는 Text 삭제시 위젯명.delete(0, END)로 삭제 명령이 수행되는 반면 Text Widget의 출력 Text를 지우는 명령 을 동일한 방법으로 수행 시 잘못된 텍스트 인덱스 오류가 발생하게 됩니다. 이 오류의 해결 방법에 대해 알아보도록 하겠습니다. 

 

 


  

오류 코드

 

아래와 같이 코드를 입력한 후 실행합니다.

 

( Input )

from tkinter import *

def clear():
    Entry_Box.delete(0, END)  # 정상동작
    Text_Box.delete(0, END)   # 에러발생

root = Tk()
Entry_Box = Entry(root, width = 50)
Entry_Box.grid(row = 0, column = 0)
Button(root, text = "clear", width = 10, command = clear).grid(row = 1, column = 0, sticky = W)
Text_Box = Text(root, width = 100, height = 10)
Text_Box.grid(row = 3, column = 0)
Text_Box.insert(END, "Test")

root.mainloop()

 

( Output )

 

clear 버튼 클릭 시 Entry의 Text는 삭제되나 Textbox의 Text들은 삭제되지 않고 Tcl.Error가 발생합니다.

 


 

해결 ( 오류 코드 수정 )

 

아래와 같이 0을 1.0으로 수정 합니다.

 

( Input )

    Text_Box.delete(1.0, END)   # 0 → 1.0으로 변경

 

( Output )

 

Text Box 내 Text들이 성공적으로 삭제된 것을 볼 수 있습니다.

 


 

마무리

 

Textbox delete 수행 시 오류와 해결 방법에 대해 알아보았습니다.

728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'PYTHON > Error Solutions' 카테고리의 다른 글

(Python/Pandas) ParserError: Error tokenizing data. read_csv 파싱 에러(오류)  (0) 2022.06.27
(Python/Pandas) XLRDError, read_excel 불러오기 에러(오류)  (0) 2022.06.27
(Python/OS) OSError: [Errno 22] Invalid argument, read_excel/read_csv 불러오기 에러(오류)  (0) 2022.06.27
(Visual Studio Code) VS Code, unins000.exe 액세스 거부 에러(오류)  (0) 2022.06.16
(Python/Pyinstaller) read file error(Excel file format cannot be determined, zipfile.BadZipFile: File is not a zip file) 에러(오류)  (0) 2022.05.30
    Creatio ex nihilo
    Creatio ex nihilo
    "Life is too short, You need python"

    티스토리툴바