250x250
250x250
  • 분류 전체보기 (48)
    • Save Your TIME (1)
      • WORK SMART - RPA (0)
      • 비 전공 직장인의 업무 자동화 고군분투기 (1)
    • Make a lot of MONEY (0)
      • 부동산 (0)
    • PYTHON (45)
      • BASIC (3)
      • pandas (3)
      • tkinter (8)
      • LIBRARY | ETC (1)
      • Tips (19)
      • Error Solutions (11)
    • EXCEL (0)
      • BASIC (0)
      • TIP (0)
    • Life & Education (2)
      • 초등 수학 (2)
      • English (0)
    • TISTORY (0)
      • ABOUT BLOG (0)
      • TIP (0)
    • Reference (0)
hELLO · Designed By 정상우.
Creatio ex nihilo

Py Life

(Python Tkinter) Chapter 5. Label ( 레이블 )
PYTHON/tkinter

(Python Tkinter) Chapter 5. Label ( 레이블 )

2022. 9. 8. 13:09
728x90
반응형

"Life is too short, You need python"

Tkinter Label은 화면에 Text나 Image를 표시하는 데 사용되는 위젯입니다. Label을 사용하여 다른 위젯들을 정의하거나 빈 공간을 확보(자간, 위젯간 간격, 줄간격 등..)하는데 활용할 수 있습니다. 이번 포스팅에서는 화면에 Text 또는 Image를 표시하는 방법에 대해 알아보겠습니다.

 


 

Label ( 레이블 )

 

 

 

 

 

 

Label을 이용하여 삽입한 이미지나 도표, 그림 등에 사용되는 주석문을 생성할 수 있습니다. 

아래와 같은 작업을 할 수 있습니다.

 

( 그림 1 )

 

 


 

Syntax ( 구문 )

 

위젯을 사용 Label하려면 다음 일반 구문을 사용합니다.

 

label = ttk.Label(container, **options)

 

  • container - parent window

 

아래는 Label을 설명하기 위한 Skeleton Code 입니다.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.geometry('800x600')
root.resizable(False, False)
root.title('Label Widget Demo')

# show the label here

root.mainloop()

 


 

Option Parameters

 

Label 위젯에는 모양을 사용자 정의할 수 있는 많은 옵션이 있습니다 .

 

- 문자열 설정 -

Name Meaning Default Preference
text 표시할 문자열 - -
textvariable 표시할 문자열을 가져올 변수 - -
anchor Label내 문자열 또는 이미지의 위치 center n, ne, e, se, s, sw, w, nw, center
justify 문자열이 여러 줄 일 경우 정렬 방법 center center, left, right
wraplength 자동 줄내림 설정 너비 0 상수

 

 

- Label Form -

Name Meaning Default Preference
width Label box 너비 0 상수
height Label box 높이 0 상수
relief Label box 모양 flat flat, groove, raised, ridge, solid, sunken
borderwidth/bd Label box 테두리 두께 2 상수
background/bg Label box 배경 색상         SystemButtonFace                   color                  
foreground/fg Label 문자열 색상         SystemButtonFace                   color                  
padx 테두리와 내용의 가로(x) gap 1 상수
pady 테두리와 내용의 세로(y) gap 1 상수
font 라벨의 문자열 글꼴 설정 TkDefaultFont font
bitmap 라벨에 포함할 기본 이미지 - info, warning, error, question, questhead,
hourglass, gray12, gray25, gray50, gray75
image 라벨에 포함할 임의 이미지 - -
compound 문자열과 이미지를 동시에
표시할 때 이미지의 위치
none bottom, center, left, none, right, top
cursor*** 라벨의 마우스 커서 모양 - 커서 속성
underline n번째 문자에 밑 줄 긋기 -1  

*** Cursor 매개 변수

arrow, based_arrow_down, based_arrow_up, boat, bogosity, bottom_left_corner, bottom_right_corner, bottom_side, bottom_tee, box_spiral, center_ptr, circle, clock, coffee_mug, cross, cross_reverse, crosshair, diamond_cross, dot, dotbox, double_arrow, draft_large, draft_small, draped_box, exchange, fleur, gobbler, gumby, hand1, hand2, heart, icon, iron_cross, left_ptr, left_side, left_tee, leftbutton, ll_angle, lr_angle, man, middlebutton, mouse, pencil, pirate, plus, question_arrow, right_ptr, right_side, right_tee, rightbutton, rtl_logo, sailboat, sb_down_arrow, sb_h_double_arrow, sb_left_arrow, sb_right_arrow, sb_up_arrow, sb_v_double_arrow, shuttle, sizing, spider, spraycan, star, target, tcross, top_left_arrow, top_left_corner, top_right_corner, top_side, top_tee, trek, ul_angle, umbrella, ur_angle, watch, wait, xterm, X_cursor

 

 

- Label State -

Name Meaning Default Preference
state 상태 설정 normal normal, active, disabled
activebackground active 상태일 때 라벨의 배경 색상 SystemButtonFace color
activeforeground active 상태일 때 라벨의 문자열 색상 SystemButtonText color
disabledforeground disabeld 상태일 때 라벨의 문자열 색상 SystemDisabledText color

 

 

- Highlight Options -

Name Meaning Default Preference
highlightcolor 라벨이 선택되었을 때 색상 SystemWindowFrame color
highlightbackground 라벨이 선택되지 않았을 때 색상 SystemButtonFace color
highlightthickness 라벨이 선택되었을 때 두께*** 0 상수

*** highlightbackground를 설정하였을 경우, 라벨이 선택되지 않았을 때에도 두께가 표시됩니다.

 

 


 

Label의 활용

 

1. Basic

 

( Input )

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.geometry('800x600')
root.resizable(False, False)
root.title('Label Widget Demo')

# label with a specific font
label = ttk.Label(
    root,
    text='A Label with the Helvetica font',
    font=("Helvetica", 14))

label.pack(ipadx = 10, ipady = 10)

photo = tk.PhotoImage(file = './green_check.png')
image_label = ttk.Label(
    root,
    image=photo,
    text='Python',
    compound='top'
)

image_label.pack()

root.mainloop()

 

( Output )

 

( 그림 1 )


 

마무리

 

Tkinter Label의 사용법과 다양한 활용 방법에 대해 알아보았습니다. Chapter 6에서는 Button의 사용법과 다양한 활용 방법에 대해 알아보도록 하겠습니다.

 

 

 

 

 

 

 

728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'PYTHON > tkinter' 카테고리의 다른 글

(Python Tkinter) Chapter 7. Entry ( 엔트리 )  (0) 2022.09.14
(Python Tkinter) Chapter 6. Button ( 버튼 )  (0) 2022.09.13
(Python Tkinter) Chapter 4. place - Geometry(Layout) Managers  (0) 2022.07.28
(Python Tkinter) Chapter 3. grid - Geometry(Layout) Managers  (0) 2022.07.28
(Python Tkinter) Chapter 2. pack - Geometry(Layout) Managers  (0) 2022.07.21
    Creatio ex nihilo
    Creatio ex nihilo
    "Life is too short, You need python"

    티스토리툴바