Language/Python
[ Python ] tkinter 위젯 색상 / 폰트 변경 프로그램
곽수진
2021. 9. 14. 13:44
반응형
사용자가 작성하는 온도 변환기의 색상과 폰트를 변경하는 프로그램을 작성해보자.
from tkinter import *
def process():
temperature = float(e1.get())
mytemp = (temperature-32)*5/9
e2.insert(0, str(mytemp))
window = Tk()
l1 = Label(window, text='화씨', font = 'helvetica 16 italic')
l2 = Label(window, text='섭씨', font = 'helvetica 16 italic')
l1.grid(row = 0, column = 0)
l2.grid(row = 1, column = 0)
e1 = Entry(window, bg = '#FFE4E1', fg = '#EA5148')
e2 = Entry(window, bg = '#FFE4E1', fg = '#EA5148')
e1.grid(row = 0, column = 1)
e2.grid(row = 1, column = 1)
b1 = Button(window, text='화씨->섭씨', command = process)
b2 = Button(window, text='섭씨->화씨', font='helvetica 12')
b1.grid(row = 2, column = 0)
b2.grid(row = 2, column = 1)
window.mainloop()
▶ 글꼴은 helvetica, 크기는 16폰트, 이탤릭체의 text를 출력
l1 = Label(window, text='화씨', font = 'helvetica 16 italic')
l2 = Label(window, text='섭씨', font = 'helvetica 16 italic')
▶ window창의 배경 색과 글씨 색상을 각각 bg, fg 변수를 사용해 지정
→ 색상을 지정할 때는 직접 색상 명을 입력해도 되고, rgb 값을 입력해도 됨
e1 = Entry(window, bg = '#FFE4E1', fg = '#EA5148')
e2 = Entry(window, bg = '#FFE4E1', fg = '#EA5148')
★ rgb 색상 참고 사이트 ★
Color Hex Color Codes
Color Hex Color Codes Color-hex gives information about colors including color models (RGB,HSL,HSV and CMYK), Triadic colors, monochromatic colors and analogous colors calculated in color page. Color-hex.com also generates a simple css code for the selecte
www.color-hex.com
반응형