본문 바로가기

프로그램 개발일지

[Python] tkinter 테마 적용하기 - ttkbootstrap

반응형
 

Instagram

 

www.instagram.com

 

 

 

이번 글에선 내가 애용하는 티킨터의 테마를 적용해보자.

 

 

 

일반적으로 사용하는 티킨터는

 

 

 

import tkinter as tk

root = tk.Tk()
root.title('test')
root.geometry('300x300')


testbt = tk.Button(root,text='테스트')
testbt.pack()

root.mainloop()

 

 

 

 

 

 

이렇게 생겼다.

 

 

UI가 진짜 좀 ... 너무 구식 같다.

 

 

 

 

그래서 사용하는 방법으로 

 

 

from tkinter import ttk
import tkinter as tk

root = tk.Tk()
root.title('test')
root.geometry('300x300')
style = ttk.Style()
style.theme_use('xpnative')

testbt = ttk.Button(root,text='테스트')
testbt.pack()

root.mainloop()

 

 

 

 

 

 

 

style = ttk.Style()
style.theme_use('xpnative')

 

위 코드를 추가해주는 방법이 있었다.

 

이후 요소들은 ttk.버튼 ... 엔트리 등 해주면 됐는데,

 

이것도 좀 밋밋하다.

 

 

 

 

 

완전 예쁘고 멋진 테마를 사용하려면 깃허브나 인터넷에서 다운로드 받은 tcl 테마를 적용하는 방법이 있지만, 

이번에는 그런거 없이 간편하게 가능하도록 해보자.

 

 

 

 

 

 

 

pip install ttkbootstrap

 

 

 

 

 

먼저 ttkbootstrap 를 설치해주자.

 

 

 

 

 

import ttkbootstrap as ttk

root = ttk.Window(themename="superhero")
root.title("test")
root.geometry("400x600")

success_label = ttk.Label(root, text="성공 레이블", bootstyle="success")
success_label.pack(pady=10)

success_entry = ttk.Entry(root, bootstyle="success")
success_entry.pack(pady=10)

danger_label = ttk.Label(root, text="위험 레이블", bootstyle="danger")
danger_label.pack(pady=10)

danger_entry = ttk.Entry(root, bootstyle="danger")
danger_entry.pack(pady=10)

warning_label = ttk.Label(root, text="경고 레이블", bootstyle="warning")
warning_label.pack(pady=10)

warning_entry = ttk.Entry(root, bootstyle="warning")
warning_entry.pack(pady=10)

info_label = ttk.Label(root, text="정보 레이블", bootstyle="info")
info_label.pack(pady=10)

info_entry = ttk.Entry(root, bootstyle="info")
info_entry.pack(pady=10)

success_button = ttk.Button(root, text="성공 버튼", bootstyle="success")
success_button.pack(pady=10)

danger_button = ttk.Button(root, text="위험 버튼", bootstyle="danger")
danger_button.pack(pady=10)

warning_button = ttk.Button(root, text="경고 버튼", bootstyle="warning")
warning_button.pack(pady=10)

info_button = ttk.Button(root, text="정보 버튼", bootstyle="info")
info_button.pack(pady=10)

root.mainloop()

 

 

 

 

 

root = ttk.Window(themename="superhero")

 

위 사진은 superhero를 적용한 모습.

밑에 나오는 애들도 사진, 적용 코드 이다.

헷갈리지 말자 !

 

 

 

 

 

 

 

root = ttk.Window(themename="flatly")

 

 

 

 

 

 

 

root = ttk.Window(themename="cosmo")

 

 

 

 

 

 

 

 

root = ttk.Window(themename="journal")

 

 

 

 

 

 

 

 

root = ttk.Window(themename="sandstone")

 

 

 

 

 

 

root = ttk.Window(themename="yeti")

 

 

 

 

root = ttk.Window(themename="litera")

 

 

 

 

 

 

root = ttk.Window(themename="united")

 

 

 

 

 

 

 

root = ttk.Window(themename="darkly")

 

 

 

 

 

root = ttk.Window(themename="minty")

 

 

 

 

 

 

 

root = ttk.Window(themename="lumen")

 

 

 

root = ttk.Window(themename="simplex")

 

 

 

 

 

 

 

똑같아 보이는게 몇개 있긴 한데, 다 다른 테마란다.

 

개인적으로 darkly가 가장 멋있는거 같다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

[종합 매크로] 공지사항

---업데이트 예정

myworld1004.tistory.com

 

 

프로그램 주문제작:

 

 

 

주식회사 유메

#프로그램제작 #프로그램

open.kakao.com

 

 

반응형