python显示股票价格

最近有个朋友炒股 但又怕被人发现 于是用我刚学的python给他写了个看股票的东东

#coding: gbk
from Tkinter import Tk,Entry,Button,mainloop
from tkFont import Font 
import urllib2
import codecs
import threading

def getStock():
    codes 
= code.get().split(',')
    allv 
= []
    
for c in codes:
        c 
= "sh"+if c.startswith('6'else "s_sz"+c
        res 
= urllib2.urlopen('http://hq.sinajs.cn/list=%s'%c).read();
        res 
= res.replace('"','').split('=')[1].split(',')
        
if len(res) > 1:
            allv.append(res[
1])
        
else:
            allv.append(
'-.--')
    result.delete(0,
'end')
    result.insert(0,
','.join(allv))
    result.update()
    
global IsStartTake
    
if IsStartTake == True:
        t 
= threading.Timer(1.0, getStock)
        t.start()
def run():
    
global IsStartTake
    
if IsStartTake == False:
        t 
= threading.Timer(1.0, getStock)
        t.start()
    IsStartTake 
= not IsStartTake
    
IsStartTake 
= False
root 
= Tk()
root.title(
"stock")
ft 
= Font(family = ('Verdana'), size = 8 ) #字体  
code = Entry(root, font= ft,width=50)
result 
= Entry(root, font= ft,width=50)
code.pack()
result.pack()
Button(root,text
=u'开关',command = run).pack()
root.mainloop()

原文地址:https://www.cnblogs.com/Death/p/1992266.html