Tkinter Entry 위젯의 기본 텍스트를 설정하는 방법
Tkinter 에는 Tkinter Entry 위젯의 기본 텍스트를 설정하는 두 가지 방법이 있습니다.
- Tkinter
insert방법 - Tkinter
StringVar메소드
insert 위젯의 기본 텍스트를 설정하는 방법
Tkinter Entry 위젯에는 text="example"와 같은 기본 텍스트를 설정하기위한 특정 text 속성이 없습니다. 엔트리 객체가 초기화 된 후 인서트 메소드를 호출하면 엔트리 위젯의 텍스트를 삽입하는 ‘삽입’메소드가있다.
insert 메소드를 사용하여 Entry 의 기본 텍스트를 설정하는 완전한 작업 코드
import tkinter as tk
root = tk.Tk()
root.geometry("200x100")
textExample = tk.Entry(root)
textExample.insert(0, "Default Text")
textExample.pack()
root.mainloop()

textExample.insert(0, "Default Text")
insert 메소드는 텍스트를 지정된 위치에 삽입합니다. 0 은 첫 번째 문자이므로 처음에Default Text를 삽입합니다.
Tkinter Entry 위젯의 기본 텍스트를 설정하는 Tkinter StringVar 메소드
textvariable 은 Entry 위젯의 내용을 Tkinter StringVar 변수와 연관시킵니다. 적절한 연관성이 생성 된 후 StringVar 를 설정하여 Entry 위젯의 기본 텍스트를 설정할 수 있습니다.
textvariable 을 사용하여 Entry 에서 기본 텍스트를 설정하는 완전한 작업 코드
import tkinter as tk
root = tk.Tk()
root.geometry("200x100")
textEntry = tk.StringVar()
textEntry.set("Default Text")
textExample = tk.Entry(root, textvariable=textEntry)
textExample.pack()
root.mainloop()
textEntry = tk.StringVar()
textEntry.set("Default Text")
textExample = tk.Entry(root, textvariable=textEntry)
textEntry 는 StringVar 변수이며 textvariable = textEntry 에 의해 Entry 객체의 텍스트 내용과 연결됩니다.
Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.
LinkedIn Facebook