2024. 7. 30. 20:23ㆍ프로그래밍 언어/Python
Tkinter 가져오기
import tkinter as tk
from tkinter import ttk
메인 윈도우 생성
root = tk.Tk()
root.title("내 Tkinter 앱")
root.geometry("400x300")
기본 위젯
- 라벨(Label)
label = tk.Label(root, text="안녕하세요, Tkinter!")
label.pack()
- 버튼(Button)
def on_click():
print("버튼 클릭됨")
button = tk.Button(root, text="클릭하세요", command=on_click)
button.pack()
- 엔트리(Entry)
entry = tk.Entry(root)
entry.pack()
- 텍스트(Text)
text = tk.Text(root, height=5, width=30)
text.pack()
- 프레임(Frame)
frame = tk.Frame(root)
frame.pack()
레이아웃 관리
- pack()
widget.pack(side=tk.TOP, fill=tk.X)
- grid()
widget.grid(row=0, column=0)
- place()
widget.place(x=50, y=50)
고급 위젯
- 콤보박스(Combobox)
combobox = ttk.Combobox(root, values=["옵션 1", "옵션 2", "옵션 3"])
combobox.pack()
- 체크버튼(Checkbutton)
var = tk.IntVar()
checkbutton = tk.Checkbutton(root, text="체크하세요", variable=var)
checkbutton.pack()
- 라디오버튼(Radiobutton)
var = tk.StringVar()
radiobutton1 = tk.Radiobutton(root, text="옵션 1", variable=var, value="1")
radiobutton2 = tk.Radiobutton(root, text="옵션 2", variable=var, value="2")
radiobutton1.pack()
radiobutton2.pack()
- 스케일(Scale)
scale = tk.Scale(root, from_=0, to=100, orient=tk.HORIZONTAL)
scale.pack()
- 프로그레스바(Progressbar)
progressbar = ttk.Progressbar(root, orient='horizontal', mode='determinate', length=200)
progressbar.pack()
progressbar['value'] = 50
다이얼로그
- 메시지박스(Messagebox)
from tkinter import messagebox
messagebox.showinfo("제목", "정보")
- 파일 다이얼로그(File Dialog)
from tkinter import filedialog
file_path = filedialog.askopenfilename()
이벤트 바인딩
def on_key_press(event):
print("키 입력됨:", event.char)
root.bind("<KeyPress>", on_key_press)
참고 사이트:
https://docs.python.org/3/library/tkinter.html
tkinter — Python interface to Tcl/Tk
Source code: Lib/tkinter/__init__.py The tkinter package (“Tk interface”) is the standard Python interface to the Tcl/Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, inclu...
docs.python.org
https://www.pythontutorial.net/tkinter/
Tkinter Tutorial
This Tkinter tutorial helps you learn how to develop beautiful GUI applications from scratch with step-by-step guidance.
www.pythontutorial.net
Python GUIs — Create GUI applications with Python and Qt
Learn how to Create Python GUIs with Python & PyQt.
www.pythonguis.com
https://pythonbasics.org/tkinter/
Tkinter (GUI Programming) - Python Tutorial
Tkinter is a graphical user interface (GUI) module for Python, you can make desktop apps with Python. You can make windows, buttons, show text and images amongst other things. Tk and Tkinter apps can run on most Unix platforms. This also works on Windows a
pythonbasics.org
'프로그래밍 언어 > Python' 카테고리의 다른 글
Python - 4. 리스트와 문자열 심화 (0) | 2025.01.19 |
---|---|
Python - 3. 제어문 (0) | 2025.01.19 |
Python - 2. 연산과 연산자 (0) | 2025.01.19 |
Python - 1. 자료형과 변수 (0) | 2025.01.19 |
파이썬 기본 내용과 참고용 사이트 정리 (0) | 2024.07.30 |