일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- DATAPATH
- data structure
- html
- CSS
- architecture
- Linux
- github
- function
- control
- for
- instruction
- react
- computer
- javascript
- web
- MIPS
- DS
- mysql
- Algorithm
- DoM
- php
- XML
- DB
- Pipelining
- system
- Class
- MacOS
- Java
- python
- while
- Today
- Total
YYYEJI
[Python] Tkinter 본문
Tkinter 란?
파이썬 기본 패키지로 GUI 를 개발할 수 있는 Toolkit Interface 입니다.
Tkinter을 사용하기 위해서는 Tkinter 모듈을 다운로드 해야되는데 conda에서 다운로드해서 사용하는게 좋습니다!
↓↓↓ Conda 사용하기 ↓↓↓
[Python] MacOS에서 Conda 사용하기
↓↓↓ 콘다 설치하기 위해서는 아래 링크로 들어가주세요 ↓↓↓ https://yyyeji.tistory.com/58 [Python] MacOS에서 Conda 설치하기 Conda 란 ? ? ? Anaconda는 파이썬 개발 환경을 쉽게 구축할 수 있도록 도와주
yyyeji.tistory.com
Conda가 실행된 환경에서 아래 코드를 실행해주세요.
pip install tkinter
tkinter 모듈을 다운로드 받는 명령어입니다.
먼저 완성된 화면부터 살펴보겠습니다.
import tkinter
window=tkinter.Tk()
window.title("First Window")
window.geometry("640x400")
window.resizable(False, False)
label=tkinter.Label(window, text="\n\nkkkk")
label.pack()
window.mainloop()
지금부터는 하나씩 코드를 살펴보겠습니다.
↓↓↓ Conda를 실행시키고 tkinter 모듈을 다운로드 해줍니다. ↓↓↓
pip install tkinter
↓↓↓ tkinter 모듈을 다운로드 했다면 import를 해줍니다. ↓↓↓
import tkinter
↓↓↓ Tk inter에 대한 객체를 하나 생성해 줍니다. ↓↓↓
window=tkinter.Tk()
↓↓↓ Window의 title을 지정해 줍니다. ↓↓↓
window.title("First Window")
↓↓↓ Window의 size를 지정해 줍니다. ↓↓↓
window.geometry("640x400")
↓↓↓ Window가 실행되고 창의 size를 조절할 수 있습니다. ↓↓↓
✓ window.resizable(상하, 좌우)
✓ True일 경우에는 window의 상하 size 조절 가능
✓ True일 경우에는 window의 좌우 size 조절 가능
window.resizable(True, True)
↓↓↓ Window에 label를 띄울 수 있습니다. ↓↓↓
✓ .pack()을 해줘야 window에 label이 띄어집니다.
label=tkinter.Label(window, text="\n\nkkkk")
label.pack()
↓↓↓ Window을 화면에 보여줍니다. ↓↓↓
window.mainloop()
button 생성
----------------------------------------------------------------------------------------------------------------------
btn = tkinter.Button(window, text="Click Me!")
btn.pack()
Entry 생성
----------------------------------------------------------------------------------------------------------------------
var_name = tkinter.StringVar()
txt_name = tkinter.Entry(window, textvariable=var_name)
txt_name.pack()
Listbox 생성
----------------------------------------------------------------------------------------------------------------------
listbox = tkinter.Listbox(window, height = 0, selectmode="extended")
listbox.insert(0, "C")
listbox.insert(0, "JAVA")
listbox.insert(0, "Python")
listbox.pack()
Check box 생성
----------------------------------------------------------------------------------------------------------------------
CheckVar1 = tkinter.IntVar()
CheckVar2 = tkinter.IntVar()
CheckVar3 = tkinter.IntVar()
c1 = tkinter.Checkbutton(window,text="C",variable=CheckVar1)
c2 = tkinter.Checkbutton(window,text="Java",variable=CheckVar2)
c3 = tkinter.Checkbutton(window,text="Python",variable=CheckVar3)
c1.pack()
c2.pack()
c3.pack()
Radio box 생성
----------------------------------------------------------------------------------------------------------------------
programming_var = tkinter.IntVar()
p1 = tkinter.Radiobutton(window, text="C", value = 1, variable = programming_var)
p2 = tkinter.Radiobutton(window, text="Java", value = 2, variable = programming_var)
p3 = tkinter.Radiobutton(window, text="Python", value = 3, variable = programming_var)
p1.pack()
p2.pack()
p3.pack()
◡̈
'Python' 카테고리의 다른 글
[Python] Streamlit 배포하기 (0) | 2022.11.24 |
---|---|
[Python] Streamlit (0) | 2022.11.21 |
[Python] 예외처리 (0) | 2022.11.19 |
[Python] 파일 다루기 (2) | 2022.11.19 |
[MacOS] Conda : command not found Error (0) | 2022.11.09 |