티스토리 뷰
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
Python,tkinter 속성값의 설정 및 확인방법
python,tkinter,config,configure,mm,pixel,color,ms,font,photoimage
-. 위젯의 parameter값 설정하는 3가지 방법
첫번째, 위젯객체 생성시 parameter값 지정하기
위젯객체 생성시 지정하지 않는 parameter값은 기본값이 사용된다.
>Mywidget=tkinter.Frame(root,background="red")
두번째, 객체 생성후 configure()메서드 이용하여 parameter값 변경하기
> Mywidget.configure(background="red")
> Mywidget.config(background="red")
세번째, 사전형식을 이용하여 parameter값 변경하기
> Mywidget["background"]="red"
-. 위젯의 parameter값을 확인하는 3가지 방법
첫번째, 모든 parameter값 확인하기
configure()메서드에 아무런 인자도 넣지 않으면, 모든 parameter값이 반환된다.
> Mywidget.configure()
> Mywidget.config()
두번째, configure()메서드이용하여 특정parameter값만 확인하기
configure()메서드에 확인하고자 하는 parameter값을 텍스트형식으로넣어주면 해당 parameter값이 반환된다.
> Mywidget.configure("background")
세번째, 사전형식으로 특정parameter값 확인하기
> Mywidget["background"]
-. 위젯parameter값의 종류와 단위
boolean : 속성의 있고 없고를 나타내는 값
parameter중 1(True) 또는 0(False)만 값으로 받는것들이 있다.
해당 속성을사용하느냐 사용하지 않느냐를 결정하는 parameter로서,
1은 True를 의미하고, 0은 False를 의미한다.
parameter설명부분에서해당 단위가 사용되는 parameter에는 "boolean"으로 표시를 해두었다.
mm/pixel : 크기 및 두께를 설정하는 parameter값의 단위 (pixel과 mm)
크기 및 두께등을지정하는 parameter에는 mm와 pixel로서 2가지 단위로 지정이 가능하다.
pixel : 입력되는 값이숫자로만 이루어질경우 pixel단위이며, str(), int(),float() 형 모두 사용이 가능하다.
즉, 3, 3.77, "3", "3.77" 이와같은 형식으로 입력시 pixel단위로 설정된다.
mm : 입력되는 값에 'm'단위가 붙을경우 mm단위이며,mm단위의 입력은 str()형식으로만 입력해야한다.
즉, "1m", "1.3m" 이와같은 형식으로 입력시 mm단위로 설정된다.
1mm는 약 3.77pixel이다.
parameter설명부분에서해당 단위가 사용되는 parameter에는 "mm/pixel"로 표시를 해두었다.
color : 색상정보를 사용하는 parameter값 (색상이름과 색상코드)
배경 또는 문자의색상을 지정하기 위한 parameter값으로는 색상이름과 색상코드로2가지의 값으로 지정이 가능하다.
색상이름 : "red", "green", "blue","white", "black" 등 일반적으로 알고 있는 색상의 이름
색상코드 : "#ff0000" 과 같은 형식으로 이루어진 색상코드값이다.
색상코드값은 tkinter.colorchooser모듈을 통하여 얻을수 있으며,
RGB코드값이라고 보면 된다
>>> import tkColorChooser
>>> color = tkColorChooser.askcolor() #색상 선택창 발생
#색상을 선택후 확인을 누르면 값이 반환됨
>>> color
((97.37890625, 208.8125, 224.875), '#61d0e0')
>>> color[1]
'#61d0e0'
parameter설명부분에서해당값이 사용되는 parameter에는 "color"로 표시를 해두었다.
ms : microsecond(ms)를 사용하는 parameter값 (1/1000초)
텍스트커서의깜박이는 시간 또는 예약작업을 지정하는 시간에 사용되는 parameter값의 단위에는 microsecond가 사용된다.
입력가능한 데이터형은 int()형만 가능하며, 1초는1000ms와 동일하다.
ex) 1초 후에 root창을 없애는 예
root.after(1000,root.destroy)
parameter설명부분에서해당단위가 사용되는 parameter에는 "ms"로표시를 해두었다.
numberof characters : 위젯의 크기에 사용되는 단위(문자의 갯수)
문자의 갯수란parameter의 값이 10일 경우 최대 10개의 문자를 보여줄수 있는 크기를 의미한다.
입력가능한 값은정수로만 가능하며, str(), int()형으로 입력이 가능하다
즉, "10", 10 와 같이 입력이 가능하다.
parameter설명부분에서해당단위가 사용되는 parameter에는 "number of characters"로 표시를 해두었다.
font : 문자열의 글꼴을 지정하는 parameter값 (tkinter.font.Font클래스)
tkinter.font.Font클래스로 font객체를 생성하여 parameter값에 사용한다.
생성자 : tkinter.font.Font(root=None,font=NOne,name=None,exists=False,**options)
-. Font클래스의 **options 인자의 종류
family : 글꼴
글꼴의 모양을위한 option, 값은 글꼴명이 사용된다.
값 : 'Courier', 'Curlz MT' 등등
size : 크기
글꼴크기를 지정하는option, 값은 int자료형을 사용한다.
weight : 진하게
기본값은 'normal'이며, 글꼴을 진하게 표시할 weight값을 'bold'로 지정하면 된다.
값 : 'normal', 'bold'
slant : 기울임
기본값은 'roman'이며, 글꼴을 기울임으로 표시할경우 slant값을 'italic'으로 지정하면 된다.
값 : 'roman', 'italic'
underline : 밑줄
밑줄표시용 option, 값은 Boolean형을 사용한다.
값 : True, False
overstrike : 취소선
취소선표시용option, 값은 Boolean형을 사용한다.
값 : True, False
아래는 글꼴객체를이용하여 글꼴을 지정하는 예이다.
ex) Python_tkinter_font_01.py
# -*- encoding:utf8 -*-
# Python version in the development environment 2.7.11
from Tkinter import *
import tkFont
class APP:
def __init__(self, root):
self.myroot = root
#---font객체생성---
fontobject = tkFont.Font(root,family='Courier',
size=15,
weight='bold',
slant='italic',
underline=True,
overstrike=True)
#---font객체를 적용할 Label생성---
self.WidgetLabel = Label(root,text="Hello Python")
self.WidgetLabel['font'] = fontobject #font parameter에 font객체적용
self.WidgetLabel.pack()
root = Tk()
app = APP(root)
root.mainloop()
# Python version in the development environment 2.7.11
from Tkinter import *
import tkFont
class APP:
def __init__(self, root):
self.myroot = root
#---font객체생성---
fontobject = tkFont.Font(root,family='Courier',
size=15,
weight='bold',
slant='italic',
underline=True,
overstrike=True)
#---font객체를 적용할 Label생성---
self.WidgetLabel = Label(root,text="Hello Python")
self.WidgetLabel['font'] = fontobject #font parameter에 font객체적용
self.WidgetLabel.pack()
root = Tk()
app = APP(root)
root.mainloop()
실행화면
parameter설명부분에서해당객체가 사용되는 parameter에는 "font"로 표시를 해두었다.
image : Label, Button, Canvas, Text위젯에 이미지를 표시할때 사용됨 (이미지파일)
tkinter.PhotoImage클래스로 PhotoImage객체를 생성하여 parameter값으로 사용한다.
생성자 : tkinter.PhotoImage(name=None,cnf={},master=None, **kw)
PhotoImage에서 사용되는 이미지는 "grayscale"또는 "true color image" 중 하나이며, 파일확장자는 GIF,PGM,PPM이미지를 사용한다.
아래는 Label에 이미지파일을 출력하는 방법이다.
ex) python_tkinter_photoimage_01.py
# -*- encoding:utf8 -*-
# Python version in the development environment 2.7.11
import os
os.chdir(os.path.dirname(__file__))
from Tkinter import *
root = Tk()
img = PhotoImage(file='sample.gif') #PhotoImage객체 생성
Label(root, image=img).pack()
root.mainloop()
# Python version in the development environment 2.7.11
import os
os.chdir(os.path.dirname(__file__))
from Tkinter import *
root = Tk()
img = PhotoImage(file='sample.gif') #PhotoImage객체 생성
Label(root, image=img).pack()
root.mainloop()
실행화면
parameter설명부분에서해당객체가 사용되는 parameter에는 "image"로 표시를 해두었다.
'Python > tkinter' 카테고리의 다른 글
Python,tkinter Button (0) | 2017.01.20 |
---|---|
Python,tkinter Tk (0) | 2017.01.20 |
Python,tkinter command & bind [명령어묶기와 사건묶기] (0) | 2017.01.18 |
Python,tkinter pack() [공간 다루기] (0) | 2016.06.16 |
Python,tkinter 틀의 신축성[부품이 있을때와 없을때의 차이] (0) | 2016.06.15 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Linux
- 리눅스
- activebackground
- tkinter command & bind [명령어묶기와 사건묶기] Python
- 상수
- apache
- Private
- borderwidth
- Composite Key
- Python
- checkbutton
- FetchType
- Java
- highlightthickness
- highlightbackground
- disabledforeground
- command
- 폼
- JPA
- activeforeground
- onetomany
- ManyToOne
- fetch join
- Module
- tkinter
- IdClass
- Excel
- 파이썬
- vba
- indicatoron
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함