반응형
1. 윈도우
기본적인 윈도우 생성 코드입니다.
from tkinter import *
window = Tk()
window.title("tkinter 테스트") # 타이틀 설정
window.geometry('320x240') # 윈도우 사이즈 설정
window.mainloop()
2. 라벨
윈도우에 폰트 속성을 적용한 라벨을 사용해 보았습니다.
from tkinter import *
window = Tk()
window.title("tkinter 테스트")
window.geometry('320x240')
label = Label(window, text="라벨테스트", font=("돋음", 30))
label.grid(column=0, row=0)
window.mainloop()
3. 버튼
버튼을 생성 후 클릭시 처리될 이벤트 함수를 작성 후 연결시켜 보았습니다. 버튼 클릭시 "버튼을 누름" 텍스트가 라벨에 보여집니다.
from tkinter import *
def pressed(): # 버튼 클릭 이벤트
label.configure(text="버튼을 누름")
window = Tk()
window.title("tkinter 테스트")
window.geometry('320x240')
label = Label(window, text="라벨테스트", font=("돋음", 30))
label.grid(column=0, row=0)
# 버튼 파라미터로 텍스트/배경색/전경색/이벤트 설정
button = Button(window, text="버튼테스트", bg="blue", fg="white", command=pressed)
button.grid(column=0, row=1)
window.mainloop()
반응형
'Software > Python' 카테고리의 다른 글
[Python] tkinter 메세지박스/스핀박스/프로그래스바 사용하기 (0) | 2021.01.12 |
---|---|
[Python] tkinter 텍스트 입력 창/ 콤보박스/체크박스/라디오버튼 사용하기 (0) | 2021.01.11 |
[Python] single, double, triple quotes [작은(홑)/큰(겹)/삼중 따옴표] (0) | 2020.12.31 |
[Python] Visual Studio Code(VSCode)에서 Python 실행하기 (0) | 2020.12.10 |
[Python] Python 설치하기 (0) | 2020.12.10 |
댓글