카테고리 없음
tkinter 사용법 (완전 기초)
아야옹이다
2023. 8. 8. 11:21
반응형
tkinter 사용법 (완전 기초)
파이썬 GUI : tkinter 사용법 (완전 기초)
1. Tkinter의 기본 문장
Tkinter는 파이썬에 기본 내장되어 있기 때문에 별도로 설치할 필요가 없습니다.
python - import tkinter as tk
- window = tk.Tk()
- window.mainloop()
위 코드는 Tkinter를 사용하여 윈도우 창을 생성하는 가장 간단한 방법입니다.
2. Tkinter 위젯
Tkinter에서는 다양한 위젯을 사용할 수 있습니다. 아래는 대표적인 위젯들입니다.
2.1 Label
- label = tk.Label(window, text="Hello World!")
- label.pack()
2.2 Button
- button = tk.Button(window, text="Click Me!")
- button.pack()
2.3 Entry
- entry = tk.Entry(window)
- entry.pack()
2.4 Text
- text = tk.Text(window)
- text.pack()
2.5 Listbox
- listbox = tk.Listbox(window)
- listbox.pack()
2.6 Checkbutton
- checkbutton = tk.Checkbutton(window, text="Check Me!")
- checkbutton.pack()
2.7 Radiobutton
- radiobutton = tk.Radiobutton(window, text="Option 1")
- radiobutton.pack()
- radiobutton = tk.Radiobutton(window, text="Option 2")
- radiobutton.pack()
3. Tkinter 레이아웃 관리자
Tkinter에서는 다양한 레이아웃 관리자를 사용할 수 있습니다. 아래는 대표적인 레이아웃 관리자들입니다.
3.1 Pack
- label1 = tk.Label(window, text="Label 1")
- label1.pack()
- label2 = tk.Label(window, text="Label 2")
- label2.pack()
- label3 = tk.Label(window, text="Label 3")
- label3.pack()
3.2 Grid
- label1 = tk.Label(window, text="Label 1")
- label1.grid(row=0, column=0)
- label2 = tk.Label(window, text="Label 2")
- label2.grid(row=0, column=1)
- label3 = tk.Label(window, text="Label 3")
- label3.grid(row=1, column=0)
3.3 Place
- label1 = tk.Label(window, text="Label 1")
- label1.place(x=0, y=0)
- label2 = tk.Label(window, text="Label 2")
- label2.place(x=50, y=50)
- label3 = tk.Label(window, text="Label 3")
- label3.place(x=100, y=100)