'python'에 해당되는 글 15건

tk listbox-2

python 2016. 2. 2. 16:26

activestyle [default value:'underline']

Listbox에서 선택된 아이템의 표시형태를 지정한다.

dotbox값은 선택된 아이템에 점선테두리효과를 준다.

none값은 선택된 아이템에 블록 처리 외에 아무런 효과를 주지 않는다.

underline값은 선택된 아이템의 문자열에 밑줄효과를 준다.

: 'dotbox', 'none', 'underline'

 

background = bg [default value:'SystemWindow'] : color

Listbox위젯의 배경색

 

borderwidth = bd [default value:1] : mm/pixel

Listbox위젯의 테두리두께

 

cursor [default value:'']

Listbox위젯의 마우스커서모양

: "arrow", "circle", "clock", "cross", "dotbox", "exchange", "fleur", "heart", "heart", "man", "mouse", "pirate", "plus", "shuttle", "sizing", "spider", "spraycan", "star", "target", "tcross", "trek", "watch" 등등

 

disabledforeground [default value:'SystemDisabledText'] : color

Listbox위젯이 disabled상태일때 위젯의 문자열 색

 

exportselection [default value:1] : boolean

 

font [default value:'TkDefaultFont'] : font

Listbox위젯에 표시할 문자열의 글꼴

값으로는 font객체가 사용되며, 글꼴객체생성방법은 아래 URL을 참조하길 바란다.

http://blog.naver.com/dudwo567890/130167555486

 

foreground = fg [default value:'SystemButtonText'] : color

Listbox위젯의 문자열 색

 

height [default value:10] : number of characters

Listbox위젯의 세로크기

값을 0으로 주면 아이템의 개수에 맞춰서 Listbox의 크기가 자동으로 조절된다.

 

highlightbackground [default value:'SystemButtonFace'] : color

Listbox위젯이 선택되지 않았을 때의 하이라이트 색

 

highlightcolor [default value:'SystemWindowFrame'] : color

Listbox위젯이 선택되었을 때의 하이라이트색

 

highlightthickness [default value:1] : mm/pixel

Listbox위젯이 선택되었을 때와 선택되지 않았을 때를 구분하는 하이라이트의 두께

 

listvariable [default value:''] :

Listbox위젯의 항목을 저장하는 Tk변수(StringVar)

Tk변수를 이용하여 Listbox에 항목을 입력할 수도 있고,

Listbox에 항목을 입력하여 Tk변수에 저장할 수도 있다.

 

relief [default value:'sunken']

Listbox위젯의 테두리모양

: "flat", "groove", "raised", "ridge", "solid", "sunken"

 

selectbackground [default value:'SystemHighlight'] : color

Libox위젯의 항목을 선택 할 때 블록처리 되는 부분의 배경색상

 

selectborderwidth [default value:0] : mm/pixel

Listbox위젯의 항목을 선택할 때 블럭처리되는 부분의 테두리두께

 

selectforeground [default value:'SystemHighlightText'] : color

Listbox위젯의 항목을 선택할 때 블럭처리되는 부분의 문자열 색

 

-. selectmode [default value:'browse']

: 'single', 'browse', 'multiple', 'extend'

 

-. setgrid [default value:0]

 

-. state [default value:'normal']

Listbox위젯의 상태 값

: 'disabled', 'normal

 

-. takefocus [default value:'']

 

-. width [default value:20] : number of characters

Listbox위젯의 가로크기

값을 0으로 주면 문자열의 길이에 맞춰서 Listbox의 크기가 자동으로 조절된다.

 

-. xscrollcommand [default value:''] :

Listbox위젯에 가로스크롤을 사용하고 싶을 때 Scrollbar객체를 지정하여 사용

 

-. yscrollcommand [default value:''] :

Listbox위젯에 세로스크롤을 사용하고 싶을 때 Scrollbar객체를 지정하여 사용

 

'python' 카테고리의 다른 글

tk listbox  (0) 2016.02.02
연달아 창 띄우기  (0) 2016.02.02
python gmail보내기  (0) 2016.02.01
tkninter tk  (0) 2016.01.28
Tkinter 기초  (0) 2016.01.28
블로그 이미지

유정쓰

,

tk listbox

python 2016. 2. 2. 16:18
from tkinter import*

root=Tk()


listbox=Listbox(root)


listbox.insert(1,"Python")
listbox.insert(
2,"c++")
listbox.insert(
3,"c#")
listbox.insert(
4,"java")
listbox.insert(
5,"php")
listbox.insert(
6,"html")
listbox.insert(
7,"css")
listbox.insert(
8,"arduino")
listbox.pack()


root.mainloop()

 

 

'python' 카테고리의 다른 글

tk listbox-2  (0) 2016.02.02
연달아 창 띄우기  (0) 2016.02.02
python gmail보내기  (0) 2016.02.01
tkninter tk  (0) 2016.01.28
Tkinter 기초  (0) 2016.01.28
블로그 이미지

유정쓰

,

연달아 창 띄우기

python 2016. 2. 2. 15:35

# -*- coding : cp949 -*-

from tkinter import *

class App:
   
def __init__(self, root, use_geometry, show_buttons):
       fm=Frame(root,
width=300, height=300, bg="blue")
        fm.pack(
side=TOP, expand=NO, fill=NONE)
       
if use_geometry:
            root.geometry(
"600x600")

       
if show_buttons:

            Button(fm,
text="안녕",width=10).pack(side=LEFT)
            Button(fm,
text="하세요",width=10).pack(side=LEFT)
            Button(fm,
text="반가워요.",width=10).pack(side=LEFT)
#버튼의 이름


case=0

for use_geometry in (0,1):

   
for show_buttons in (0,1):

        case = case +
1

       
root=Tk()
        root.wm_title(
"Case " + str(case)) #창의 제목
       
display=App(root, use_geometry, show_buttons)
        root.mainloop()

 

하나를 끄면 그 다음 창이 뜨게 되는 구조

 

 

'python' 카테고리의 다른 글

tk listbox-2  (0) 2016.02.02
tk listbox  (0) 2016.02.02
python gmail보내기  (0) 2016.02.01
tkninter tk  (0) 2016.01.28
Tkinter 기초  (0) 2016.01.28
블로그 이미지

유정쓰

,

python gmail보내기

python 2016. 2. 1. 09:28

Gmail로 메일보내기 <<

Gmail을 통해서 메일을 보내거나 받아오기 위한 정보는 아래와 같다.

받는 메일 서버(POP3)

SSL 필요

주소 : pop.gmail.com

SSL사용 : YES

포트 : 995

보내는 메일 서버(SMTP)

TLS 필요

주소 : smtp.gmail.com

인증사용 : YES

STARTTLS사용 : YES

포트 : 465 or 587

이메일주소

계정@gmail.com

password

Gmail계정 Password

 

그 중 SMTP에 관련된 내용을 보면, 서버주소는 smtp.gmail.com이고 포트번호는 587혹은 465번을 써야 하고,

STARTTLS를 써야 한다고 명시되어 있는데, TLS(Transport Layer Security) TCP/IP와 같은 통신에서 사용하는 암호규약입니다.

STARTTLS는 텍스트에 대한 암호화를 업그레이드하고 확장한 버전이다.

Python STARTLS를 위해 smltplib모듈의 starttls()메서드를 지원한다.

>>> import smtplib

>>> s=smtplib.SMTP('smtp.gmail.com',587)

>>> s.ehlo()

(250, b'mx.google.com at your service, [114.111.62.248]\nSIZE 35882577\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES')

>>> s.starttls()

(220, b'2.0.0 Ready to start TLS')

>>> s.ehlo()

(250, b'mx.google.com at your service, [114.111.62.248]\nSIZE 35882577\n8BITMIME\nAUTH LOGIN PLAIN XOAUTH XOAUTH2\nENHANCEDSTATUSCODES')

>>> s.login('hyj****@gmail.com','****')

(235, b'2.7.0 Accepted')

 

smtp.gmail.com의 인증에 성공한 것을 보실 수 있습니다.

 

아래는 로컬의 logo.html파일을 읽어서 메일의 내용을 생성하고, logo.png파일을 첨부파일로 하여

Gmail smtp에서 Naver메일로 메일을 발송하는 예제이다.

# -*- coding : cp949 -*-

import smtplib

from email.mime.base import MIMEBase

from email.mime.text import MIMEText

from email.mime.image import MIMEImage

 

host='smtp.gmail.com' #Gmail smtp server address

port='587' #smtp port

htmlfile='logo.html'

imagefile='logo.png'

 

sender='hyj****@gmail.com' #sender email address

recipient='hyj****@naver.com' #recipient email address

 

# Create MIMEBase

msg=MIMEBase('multipart','mixed')

msg['Subject']='Test Email in html.logo'

msg['From']=sender

msg['To']=recipient

 

# Create MIMEHtml

htmlF=open(htmlfile,'rb')

htmlPart=MIMEText(htmlF.read(),'html',_charset='utf-8')

htmlF.close()

 

# Create MIMEImage

imageF=open(imagefile,'rb')

imagePart=MIMEImage(imageF.read())

imageF.close()

 

# attach html,image

msg.attach(imagePart)

msg.attach(htmlPart)

 

# mail send

s=smtplib.SMTP(host,port)

s.set_debuglevel(1) #debuging

s.ehlo()

s.starttls()

s.ehlo()

s.login(sender,'****')

s.sendmail(sender,[recipient],msg.as_string())

s.close()

 

위를 실행하면 Gmail에서 보낸메일을 naver메일로 확인할수 있다.

 

※ Python3 이전 버젼의 MIME

이메일관련 모듈이름 상당수가 python3에서 이름이 변경되었다

예를 들면 email.mime.text.MIMEText python3이전 버전에서는

email.MIMEText.MIMEText이다.

Python3에서 기존 코드를 참고하여 프로그램을 작성하는 경우,

모듈의 이름이 변경된 경우를 반드시 확인하여야 한다.

 

 

'python' 카테고리의 다른 글

tk listbox  (0) 2016.02.02
연달아 창 띄우기  (0) 2016.02.02
tkninter tk  (0) 2016.01.28
Tkinter 기초  (0) 2016.01.28
파일 관리  (0) 2016.01.27
블로그 이미지

유정쓰

,

tkninter tk

python 2016. 1. 28. 14:52

 Tk에서 쓰이는 parameter

 

1. background = bg [default value:'SystemButtonFace'] : color

root창의 배경 색

 

2. borderwidth = bd [default value:0] : mm/pixel

root창의 테두리 두께

 

3. class [default value:'Tk']

class option after widget is created

 

4. colormap [default value:'']

colormap option after widget is created

 

5. container [default value:0]

container option after widget is created

 

6. cursor [default value:''] :

root마우스커서모양

: "arrow", "circle", "clock", "cross", "dotbox", "exchange", "fleur", "heart", "heart", "man", "mouse", "pirate", "plus", "shuttle", "sizing", "spider", "spraycan", "star", "target", "tcross", "trek", "watch" 등등

 

7. height [default value:0] : mm/pixel

root창의 세로크기

root창에 위젯이 구성되면 값은 무시되고, 크기는 자동조절된다.

 

8. highlightbackground [default value:'SystemButtonFace'] : color

root창이 선택되지 않았을때의 하이라이트색

 

9. highlightcolor [default value:'SystemWindowFrame'] : color

root창이 선택되었을때의 하이라이트색

 

10. highlightthickness [default value:0] : mm/pixel

root창이 선택되었을때와 선택되지 않았을때를 구분하는 하이라이트의 두께

 

11. menu [default value:''] :

root창에 메뉴를 사용할경우 이 parameter Menu객체를 지정하여 사용함

 

12. padx [default value:'0'] : mm/pixel

root창의 테두리와 내용사이의 가로여백

 

13. pady [default value:'0'] : mm/pixel

root창의 테두리와 내용사이의 세로여백

 

14. relief [default value:'flat']

root창의 테두리모양

: "flat", "groove", "raised", "ridge", "solid", "sunken"

 

15. screen [default value:'']

screen option after widget is created

 

16. takefocus [default value:'0']

 

17. use [default value:'']

 

18. visual [default value:'']

visual option after widget is created

 

19. width [default value:0] : mm/pixel

root창의 가로크기

root창에 위젯이 구성되면 값은 무시되고, 크기는 자동조절된다.

 

 

'python' 카테고리의 다른 글

연달아 창 띄우기  (0) 2016.02.02
python gmail보내기  (0) 2016.02.01
Tkinter 기초  (0) 2016.01.28
파일 관리  (0) 2016.01.27
특수문자 사용  (0) 2016.01.27
블로그 이미지

유정쓰

,

Tkinter 기초

python 2016. 1. 28. 14:45

(간단한 창 띄우기)

From tkinter import*

Root=Tk()

Root.mainloop()

 

<from tkinter import*

root=Tk()

F=Frame(root)

F.pack()#packing

button1=Button(F)                 

button1['text']="hello"

button1['background']='green'

button1.pack()

 

root.mainloop()>

 

위 코드를 치게 되면 밑의 창이 나오게 됩니다. :-)

 

 

 

'python' 카테고리의 다른 글

python gmail보내기  (0) 2016.02.01
tkninter tk  (0) 2016.01.28
파일 관리  (0) 2016.01.27
특수문자 사용  (0) 2016.01.27
time module  (0) 2016.01.27
블로그 이미지

유정쓰

,

파일 관리

python 2016. 1. 27. 14:48

-. remove(path), unlink(path)

파일 삭제

>>> os.remove("test.txt")

>>> os.unlink("test.txt")

 

-. rename(a,b)

a b로 이름변경, a b가 다른 경로면 이동(이름변경하면서 이동도 가능) #디렉토리 생성은 불가

#파일, 디렉토리 모두 가능

>>> os.rename("test.txt","test2.txt") #같은 디렉토리 이므로 이름만 변경됨

>>> os.rename("test.txt","data/test2.txt") #data 디렉토리로 이동과 함께 파일이름 변경

 

-. renames(a,b)

a b로 이름변경, a b가 다른 경로면 이동(이름변경하면서 이동도 가능) #디렉토리 생성 가능

#파일, 디렉토리 모두 가능

>>> os.renames("test.txt","test2.txt") #같은 디렉토리 이므로 이름만 변경됨

>>> os.renames("test.txt","data/test2.txt") #data 디렉토리로 이동과 함께 파일이름 변경

 

-. stat(path)

경로에 해당하는 정보를 반환

 

>>> os.stat(".")

nt.stat_result(st_mode=16895, st_ino=1407374883559076, st_dev=0, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1353267245, st_mtime=1353267245, st_ctime=1352382813)

 

>>> os.stat("test.txt")

nt.stat_result(st_mode=33206, st_ino=2533274790427368, st_dev=0, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1353266985, st_mtime=1353266985, st_ctime=1353266985)

 

 

-. utime(path,times)

경로에 해당하는 파일에 액세시시간,수정시간을 times로 수정

#times None일경우 현재시간으로 수정됨

>>> os.utime("test.txt",None) #파일의 액세스시간과 수정시간을 현재시간으로 변경

>>> os.utime("test.txt",(1,1)) #파일의 액세스시간과 수정시간을 [19700101 09:00:01]로 변경

 

 

-. walk(top[,topdown=True[,onerror=None[,followlinks=False]]])

top으로 지정된 디렉토리를 순회하며 경로, 디렉토리명을 순차적으로 반환

- test

  +-intest.txt

  +-game

    +-ingame.txt

    +-music

      +-inmusic.txt

위와 같은 디렉토리 구조에서 해당명령어 사용시

>>> for path,dirs,files in os.walk('test'):

       print(path,dirs,files)

test ['game'] ['intest.txt']

test\game ['music'] ['ingame.txt']

test\game\music [] ['inmusic.txt']

 

 

-. umask(mask)

umask를 설정, 수행시 이전mask값 반환

umask가 수행되면 이후 오픈되는 파일이나 디렉토리에 (mode & ~umask)와 같이 적용됨

 

 

-. pipe()

※ from os import * 사용시 import 안됨, from os import fdopen 가능 혹은 os.fdopen으로 사용가능

 

파이프생성, 함수를 실행하면 읽기, 쓰기 전용 파이프의 파일 디스크립터가 반환됨

파이프는 주로 부모프로세스와 자식프로세스간의 통신을 목적으로 사용함

>>> os.pipe()

(3, 4)

 

-. fdopen(fd[,mode[,bufsize]])

파일 디스크립터를 이용해 파일 객체를 생성

 

-. popen(command[,mode[,bufsize]])

※ from os import * 사용시 import 안됨, from os import popen 가능 혹은 os.popen으로 사용가능

 

인자로 전달된 command를 수행하며 파이프를 염

#Python3에서는 Popen클래스의 사용을 권장하지만 그대로 사용할수도 있음

'python' 카테고리의 다른 글

tkninter tk  (0) 2016.01.28
Tkinter 기초  (0) 2016.01.28
특수문자 사용  (0) 2016.01.27
time module  (0) 2016.01.27
sys module  (0) 2016.01.27
블로그 이미지

유정쓰

,

특수문자 사용

python 2016. 1. 27. 14:05

<특수문자>

사용예시

의미

\n

개행 (줄바꿈)

\t

\r

캐리지 리턴

\0

(Null)

\\

문자 '\'

\'

단일 인용부호(')

\"

단일 인용부호(")

 

 

 

>>> print('\t\n다음줄')

다음줄

 

 

-. 이스케이프문자 미적용

 

>>> print(r'\t\n다음줄')
\t\n다음줄

 

 

'python' 카테고리의 다른 글

Tkinter 기초  (0) 2016.01.28
파일 관리  (0) 2016.01.27
time module  (0) 2016.01.27
sys module  (0) 2016.01.27
RANDOM  (0) 2016.01.27
블로그 이미지

유정쓰

,

time module

python 2016. 1. 27. 13:53

TIME 모듈로 시간 알아보기

 

파이썬의 time 모듈은 시간을 표시하는 함수들을 가지고 있다.

 

>>> import time

>>> print(time.time())

1453869195.147997

 

time()을 호출하여 반환된 숫자는 1970 1 1 00 00 00초 이후 지금까지의 초를 나타낸다.

 

>>> def lots_of_numbers(max):

  t1=time.time()

    for x in range(0, max):

        print(x)

    t2=time.time()

    print("걸리는 시간은 %s 초이다" %(t2-t1))

 

    

>>> lots_of_numbers(1000)

1

...

998

999

걸리는 시간은 4.318386077880859 초이다

 

위 프로그램은 먼저 time()함수를 호출하고, 반환된 값을 변수 t1에 할당한다. 세번째와 네번째 줄에 있는 코드에서 모든 숫자를 출력한다. 이 루프가 끝나면 다시 time()을 호출하여 반환된 값을 t2에 할당한다. (t2-t1)을 하면 걸린 시간을 얻을 수 있다.

 

 

ASCTIME으로 날짜 변환하기

asctime함수는 튜플로 날짜(date)를 받아서 읽을 수 있는 어떤 것으로 변환한다.

 

 

>>> import time

>>> print(time.asctime())

Wed Jan 87 13:37:00 2016

 

>>> import time

>>> t=(2020, 2, 23, 10, 30, 48, 6, 0, 0)

>>> print(time.asctime(t))

Sun Feb 23 10:30:48 2020

 

아무런 매개변수없이 asctime을 호출하면 읽을 수 있는 형태로 현재 날짜와 시간을 표시하게 된다.

매개변수로 asctime을 호출하려면 먼저 날짜와 시간에 대한 값으로 튜플을 생성한다. t의 값은 년도, , , 시간, , , 요일(0은 월요일, 1을 화요일..), 일년 중 며칠, 일광 절약 시간인지 아닌지(아니다:0, 맞다:1)을 넣는다

 

LOCALTIME으로 날짜와 시간 얻기

localtime 함수는 현재 날짜와 시간을 객체로 반환합니다.

이 값들은 asctime입력 순서와 거의 동일하다.

 

>>> import time

>>> print(time.localtime())

 

## 현재 연도와 월을 출력하려면 이들의 인덱스 위치를 사용한다

time.struct_time(tm_year=2016, tm_mon=1, tm_mday=27, tm_hour=13, tm_min=38, tm_sec=32, tm_wday=2, tm_yday=27, tm_isdst=0)

 

>>> t=time.localtime()

>>> year=t[0]

>>> month=t[1]

>>> print(year)

2015

>>> print(month)

4

 

SLEEP으로 잠깐 쉬기

sleep함수는 프로그램에 약간의 딜레이를 주거나 천천히 동작하고자 할 때 매우 유용하다.

 

>>> for x in range(1, 61):

  print(x)

    time.sleep(1)

 

이 코드는 각 숫자가 출력되는 사이에 딜레이를 추가한다. , 하나를 출력하고 1초씩 쉬라고 지정할 수 있다. 아래의 사진처럼 화면이 나오게 된다.

 

 

'python' 카테고리의 다른 글

파일 관리  (0) 2016.01.27
특수문자 사용  (0) 2016.01.27
sys module  (0) 2016.01.27
RANDOM  (0) 2016.01.27
copy module  (0) 2016.01.27
블로그 이미지

유정쓰

,

sys module

python 2016. 1. 27. 13:43

SYS 모듈로 쉘 컨트롤하기

sys모듈은 파이썬 쉘 자체를 컨트롤할 때 사용할 수 있는 시스템 함수들을 가지고 있다. exit함수, stdin stdout객체, version변수의 사용법에 대해 알아본다.

 

EXIT 함수로 쉘 종료하기

exit함수는 파이썬 쉘이나 콘솔을 멈추는 방법이다. 정말로 종료하고 싶은지를 묻는 다이얼로그가 나타날 것이고 Yes를 클릭하면 쉘이 종료된다.

 

>>> import sys

>>> sys.exit()

 

STDIN 객체로 읽기

sys모듈의 stdin객체는 사용자가 쉘에 입력한 것을 읽어서 프로그램에서 사용할 수 있도록 해준다.

 

>>> import sys

>>> v=sys.stdin.readline()

He who laughs last thinks slowest

>>> print(v)

He who laughs last thinks slowest

 

input함수와 readline함수의 차이점들 중의 하나는 readline함수는 매개변수로 지정된 글자수만큼 읽어 드린다는 것이다.

 

>>> v=sys.stdin.readline(13)

He who laughs last thinks slowest

>>> print(v)

He who laughs

 

STDOUT 객체로 쓰기

stdout객체는 쉘에 메시지를 쓸 때 사용한다. print함수와 비슷하지만, stdout write와 같은 함수들을 가지고 있는 파일 객체다.

 

>>> import sys

>>> sys.stdout.write("What does a fish say when it swims into a wall? Dam.")

What does a fish say when it swims into a wall? Dam.52

 

결과값의 마지막에 쓰여진 글자의 숫자를 나타내는 52가 나타나는 것을 알 수 있다. 화면에 얼마나 많은 글자를 썻는지 기록하기 위해서 이 값을 변수에 저장할 수도 있다.

 

내가 쓰는 파이썬 버전 확인하기

version 변수는 사용하고 있는 파이썬의 버전을 표시해주며 최신 버전을 사용하고 있는지를 확인하고자 할 때 유용할 수 있다.

 

>>> import sys

>>> print(sys.version)

3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)]

 

'python' 카테고리의 다른 글

특수문자 사용  (0) 2016.01.27
time module  (0) 2016.01.27
RANDOM  (0) 2016.01.27
copy module  (0) 2016.01.27
파일 작업  (0) 2016.01.27
블로그 이미지

유정쓰

,