VRSPACE



file 읽고 쓰기

사용자 삽입 이미지
from tkinter import *

def evClear():T.delete(1.0,END)
def evSave():
fname=e.get()
f = open(fname, 'w')
f.write(T.get(1.0,END))
f.close()
evClear()
def evInser():
fname=e.get()
f = open( fname, "r")
for line in f:
T.insert(END,str(line))
f.close()

top = Tk()
F=Frame(top, width=300, height=200)
F.pack(fill=BOTH, expand=YES)

F2=Frame(F)
F2.pack(fill=X)

e = StringVar()
Entry(F2,textvariable=e).pack(side=LEFT,fill=X, expand=YES)
e.set("a.txt")

#E = Entry(F2)
#E.pack(side=LEFT,fill=X, expand=YES)

A = Button(F2, text="File Open", command=evInser)
A.pack(side=LEFT)

F3=Frame(F)
F3.pack(fill=BOTH, expand=YES)

T = Text(F3)
T.config(background='gray')
T.config(wrap='none')
T.pack(side=LEFT,fill=BOTH, expand=YES)
S = Scrollbar(F3)
S.config(command=T.yview)
S.pack(side=RIGHT, fill=Y)        


C = Button(F, text="File Save", command=evSave)
C.pack(side=RIGHT)

D = Button(F, text="Clear", command=evClear)
D.pack(side=RIGHT)

top.mainloop()

Posted by 뭘더

2013/02/18 22:21 2013/02/18 22:21
Response
No Trackback , No Comment
RSS :
http://vrspace.co.kr/rss/response/35

파이썬 기본 인코딩 Python 3.3.0

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'
>>>

Posted by 뭘더

2013/02/18 15:54 2013/02/18 15:54
Response
No Trackback , No Comment
RSS :
http://vrspace.co.kr/rss/response/34

Timer

사용자 삽입 이미지
from tkinter import *
from threading import Timer

numi = 0.0
def evStop():
t.cancel()
def evStart():
global t
t = Timer(0.1, evPring)
t.start()
def evPring():
global numi
numi+=0.1
e.set(str(round((numi*100))/100))
evStart()
def evReset():
evStop()
global numi
numi=0.0;
e.set(str(round((numi*100))/100))

top = Tk()
F=Frame(top)
F.pack(fill=BOTH, expand=YES)

F2=Frame(F)
F2.pack(fill=BOTH)

e = StringVar()
Entry(F,textvariable=e,justify=CENTER).pack(side=LEFT,fill=BOTH, expand=YES)
e.set("0.0")

A = Button(F, text=" Start ", command=evStart)
A.pack()

A2 = Button(F, text=" Stop ", command=evStop)
A2.pack()

A3 = Button(F, text=" Reset ", command=evReset)
A3.pack()

top.mainloop()

Posted by 뭘더

2013/02/18 15:16 2013/02/18 15:16
Response
No Trackback , No Comment
RSS :
http://vrspace.co.kr/rss/response/33

파이썬 시계

사용자 삽입 이미지

from tkinter import *
import time
from datetime import date

def update_clock():
today = date.today()
now = time.strftime("%H:%M:%S")
e.set(str(today)+" | "+now)
top.after(200, update_clock)

top = Tk()
F=Frame(top)
F.pack(fill=BOTH, expand=YES)

F2=Frame(F)
F2.pack(fill=BOTH)

e = StringVar()
Entry(F,textvariable=e,justify=CENTER).pack(side=LEFT,fill=BOTH, expand=YES)

update_clock()

top.mainloop()

Posted by 뭘더

2013/02/17 16:32 2013/02/17 16:32
Response
No Trackback , No Comment
RSS :
http://vrspace.co.kr/rss/response/32

유튜브검색-자동추가

사용자 삽입 이미지
한글처리문제 있음-어려운 문제

#-*- coding: cp949 -*-
from tkinter import *
from urllib import request
import json
from threading import Timer

selection=1
def evClear():
T.delete(1.0,END)
def evInser3():
t.cancel()
def evInser2():
evClear()
evInser()
global t
t = Timer(5.0, hello)
t.start()
def hello():
n.set(str(int(n.get())+1))
evInser2()
def evInser():
if selection == 1:
urls="https://gdata.youtube.com/feeds/api/videos?q="+str(e.get())+"&v=2&start-index="+str(n.get())+"&alt=json"
else:
urls="http://gdata.youtube.com/feeds/api/users/"+str(e.get())+"/uploads?v=2&start-index="+str(n.get())+"&alt=json";
ru = request.urlopen(urls)
res=ru.read().decode("utf-8")
Jres= json.loads(res)
rest ="totalResults : "+str(Jres['feed']['openSearch$totalResults']['$t'])+" startIndex : "+str(Jres['feed']['openSearch$startIndex']['$t'])+" itemsPerPage : "+str(Jres['feed']['openSearch$itemsPerPage']['$t'])+" item : "+str(Jres['feed']['openSearch$startIndex']['$t']*Jres['feed']['openSearch$itemsPerPage']['$t'])
label.config(text = str(rest))
for Jres['feed']['entry'] in Jres['feed']['entry']:
T.insert(END,Jres['feed']['entry']['published']['$t'])
T.insert(END,"\t")
T.insert(END,Jres['feed']['entry']['id']['$t'].split(":")[3])
T.insert(END,"\t")
T.insert(END,Jres['feed']['entry']['title']['$t'])
T.insert(END,"\n")
evWrite()
def evWrite():
fname=e.get()
f = open(fname, 'a')
f.write(T.get(1.0,END))
f.close()
def sel():
selection =v.get()
label.config(text = str(selection))

top = Tk()
F=Frame(top)
F.pack(fill=BOTH, expand=YES)
F.master.title("YouTube KeyWord Search")

F2=Frame(F)
F2.pack(fill=X)

v = IntVar()
v.set("1")
Radiobutton(F2, text="keyword", variable=v, value=1,command=sel).pack(side=LEFT)
Radiobutton(F2, text="users", variable=v, value=2,command=sel).pack(side=LEFT)

e = StringVar()
Entry(F2,textvariable=e).pack(side=LEFT,fill=X, expand=YES)
e.set("starcraft")

n = StringVar()
Entry(F2,textvariable=n).pack(side=LEFT)
n.set("1")

#E = Entry(F2)
#E.pack(side=LEFT,fill=X, expand=YES)

A = Button(F2, text="YouTube Search", command=evInser)
A.pack(side=LEFT)

A2 = Button(F2, text="Auto Search", command=evInser2)
A2.pack(side=LEFT)

A3 = Button(F2, text="Stop", command=evInser3)
A3.pack(side=LEFT)

F3=Frame(F)
F3.pack(fill=BOTH, expand=YES)

T = Text(F3)
T.config(background='gray')
T.config(wrap='none')
T.pack(side=LEFT,fill=BOTH, expand=YES)
S = Scrollbar(F3)
S.config(command=T.yview)
S.pack(side=RIGHT, fill=Y)        

label = Label(F)
label.pack(side=LEFT,  fill=Y)
C = Button(F, text="Text Delete", command=evClear)
C.pack(side=RIGHT)
C = Button(F, text="Text Save", command=evWrite)
C.pack(side=RIGHT)


top.mainloop()

Posted by 뭘더

2013/02/17 15:41 2013/02/17 15:41
Response
No Trackback , No Comment
RSS :
http://vrspace.co.kr/rss/response/31

YouTube KeyWord Search

사용자 삽입 이미지
from tkinter import *
from urllib import request
import json

def evClear():T.delete(1.0,END)
def evInser():
urls="https://gdata.youtube.com/feeds/api/videos?q="+str(e.get())+"&v=2&start-index="+str(n.get())+"&alt=json"
ru = request.urlopen(urls)
res=ru.read().decode("utf-8")
Jres= json.loads(res)
T.insert(END,Jres['feed']['openSearch$totalResults']['$t'])
T.insert(END,"\t")
T.insert(END,Jres['feed']['openSearch$startIndex']['$t'])
T.insert(END," x ")
T.insert(END,Jres['feed']['openSearch$itemsPerPage']['$t'])
T.insert(END,"\n")
for Jres['feed']['entry'] in Jres['feed']['entry']:
T.insert(END,Jres['feed']['entry']['id']['$t'].split(":")[3])
T.insert(END,"\t")
T.insert(END,Jres['feed']['entry']['title']['$t'])
T.insert(END,"\n")
def evWrite():
f = open(r'c:\Python33\user\somefile.txt', 'a')
f.write(T.get(1.0,END))
f.close()

top = Tk()
F=Frame(top, width=300, height=200)
F.pack(fill=BOTH, expand=YES)
F.master.title("YouTube KeyWord Search")

F2=Frame(F)
F2.pack(fill=X)

e = StringVar()
Entry(F2,textvariable=e).pack(side=LEFT,fill=X, expand=YES)
e.set("starcraft")

n = StringVar()
Entry(F2,textvariable=n).pack(side=LEFT)
n.set("1")

#E = Entry(F2)
#E.pack(side=LEFT,fill=X, expand=YES)

A = Button(F2, text="YouTube Search", command=evInser)
A.pack(side=LEFT)

F3=Frame(F)
F3.pack(fill=BOTH)

T = Text(F3)
T.config(background='gray')
T.config(wrap='none')
T.pack(side=LEFT,fill=BOTH, expand=YES)
S = Scrollbar(F3)
S.config(command=T.yview)
S.pack(side=RIGHT, fill=Y)        


C = Button(F, text="Text Delete", command=evClear)
C.pack(side=RIGHT)
C = Button(F, text="Text Save", command=evWrite)
C.pack(side=RIGHT)

top.mainloop()

Posted by 뭘더

2013/02/16 21:07 2013/02/16 21:07
Response
No Trackback , No Comment
RSS :
http://vrspace.co.kr/rss/response/30

유튜브 json파일 읽어오기- json.loads()

사용자 삽입 이미지

from tkinter import *
from urllib import request
import json

def evClear():T.delete(1.0,END)
def evInser():
ru = request.urlopen(e.get())
res=ru.read().decode("utf-8")
Jres= json.loads(res)
for Jres['feed']['entry'] in Jres['feed']['entry']:
T.insert(END,Jres['feed']['entry']['id']['$t'])
T.insert(END,"\t")
T.insert(END,Jres['feed']['entry']['title']['$t'])
T.insert(END,"\n")

top = Tk()
F=Frame(top, width=300, height=200)
F.pack(fill=BOTH, expand=YES)

F2=Frame(F)
F2.pack(fill=X)

e = StringVar()
Entry(F2,textvariable=e).pack(side=LEFT,fill=X, expand=YES)
e.set("http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?v=2&alt=json")

#E = Entry(F2)
#E.pack(side=LEFT,fill=X, expand=YES)

A = Button(F2, text="Get url", command=evInser)
A.pack(side=LEFT)

T = Text(F)
T.config(background='gray')
T.pack(side=TOP,fill=BOTH, expand=YES)



C = Button(F, text="??용뮞??筌왖€?怨뚮┛", command=evClear)
C.pack(side=RIGHT)

top.mainloop()

Posted by 뭘더

2013/02/16 19:45 2013/02/16 19:45
Response
No Trackback , 94 Comments
RSS :
http://vrspace.co.kr/rss/response/29

웹페이지 소스보기.. request.urlopen()

사용자 삽입 이미지
from tkinter import *
from urllib import request

# 먼저 사건 처리자를 만든다.
def evClear():T.delete(1.0,END)
def evInser():
wf = request.urlopen(e.get())
text=wf.read()
T.insert(END,text)

top = Tk()
F=Frame(top, width=300, height=200)
F.pack(fill=BOTH, expand=YES)

F2=Frame(F)
F2.pack(fill=X)

e = StringVar()
Entry(F2,textvariable=e).pack(side=LEFT,fill=X, expand=YES)
e.set("http://")

#E = Entry(F2)
#E.pack(side=LEFT,fill=X, expand=YES)

A = Button(F2, text="Get url", command=evInser)
A.pack(side=LEFT)

T = Text(F)
T.config(background='gray')    
T.pack(side=TOP,fill=BOTH, expand=YES)



C = Button(F, text="텍스트 지우기", command=evClear)
C.pack(side=RIGHT)

top.mainloop()

Posted by 뭘더

2013/02/16 13:43 2013/02/16 13:43
Response
No Trackback , 103 Comments
RSS :
http://vrspace.co.kr/rss/response/28

파이썬 독특한거 ...들여쓰기...한글처리

실행 단위를 들여쓰기로 나나낸다...
콜론으로 : 블록시작을 알리고
들여써야 된다.

파일을 일거나나 저장할때
유니코드 문제가 있음.
복잡하고 어려워..다음으로 미룸

Posted by 뭘더

2013/02/16 02:29 2013/02/16 02:29
Response
No Trackback , 16 Comments
RSS :
http://vrspace.co.kr/rss/response/26

위젯으로 레이아웃 잡기

#!/usr/bin/python
from tkinter import *

# 먼저 사건 처리자를 만든다.
def evClear():T.delete(1.0,END)
def  evInser():T.insert(END,E.get()+"\n")

top = Tk()
F=Frame(top, width=300, height=200)
F.pack(fill=BOTH, expand=YES)

F2=Frame(F)
F2.pack(fill=X)

E = Entry(F2)
E.pack(side=LEFT,fill=X, expand=YES)

A = Button(F2, text="텍스트 추가", command=evInser)
A.pack(side=LEFT)

T = Text(F)
T.config(background='gray')    
T.pack(side=TOP,fill=BOTH, expand=YES)

C = Button(F, text="텍스트 지우기", command=evClear)
C.pack(side=RIGHT)

top.mainloop()

사용자 삽입 이미지

Posted by 뭘더

2013/02/16 01:05 2013/02/16 01:05
Response
No Trackback , No Comment
RSS :
http://vrspace.co.kr/rss/response/25


Site Stats

Total hits:
23779
Today:
211
Yesterday:
0

Calendar

«   2013/05   »
      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 29 30 31