疯陈盯盘

from tkinter import *
import urllib.request
from PIL import Image, ImageTk
import os,io,threading,time
from tkinter import messagebox
from win32api import GetSystemMetrics

print(GetSystemMetrics(0),GetSystemMetrics(1))

win=Tk()
win.title('疯陈')
#win.geometry('280x40+1620+960')
win.geometry('280x40+'+str(GetSystemMetrics(0)-310)+'+'+str(GetSystemMetrics(1)-120))
#win.attributes("-toolwindow", 1)
win.resizable(width=False,height=False)

stock_name=StringVar()
stock_name.set('海王生物')
Label(win,textvariable=stock_name).grid(row=0,column=0,padx=5,pady=5)
stock_zhang=StringVar()
stock_zhang.set('10.00%')
Label(win,textvariable=stock_zhang).grid(row=0,column=1,padx=5,pady=5)
stock_code=StringVar()
stock_code.set('000078')
e = Entry(win,textvariable=stock_code,width=8)
e.grid(row=0,column=2,padx=5,pady=5)

netDateUrl = 'http://hq.sinajs.cn/list=sz000078'

#获取股票数据当日数据
def getStockDate(netDateUrl):
    html = urllib.request.urlopen(netDateUrl).read()
    html = html.decode('gbk')
    stock_dict={}
    stock_dict['code'] = html[13:19]
    temp = html[21:246].split(',')
    stock_dict['name'] = temp[0]
    stock_dict['close'] = temp[2]
    stock_dict['now'] = temp[3]
    #stock_dict['name'] = temp[0]
    #stock_dict['name'] = temp[0]
    return stock_dict



state  = True
def fun():
    while state:
        code = stock_code.get()
        url = 'http://hq.sinajs.cn/list=sz'+code
        date = getStockDate(url)
##        print(date['name'])
##        print(date['close'])
##        print(date['now'])
        now = round((float(date['now'])/float(date['close'])-1)*100,2)
        now = str(now)+'%'
        stock_name.set(date['name'])
        #print(now)
        stock_zhang.set(now)
        
def fun2():
    if e['state']==NORMAL:
        e.config(state=DISABLED)
    else:
        e.config(state=NORMAL)
    #print(e['state'])
    p = threading.Thread(target = fun)
    p.setDaemon(True)#守护进程
    p.start()



Button(win,text='查询',command=fun2,width=8).grid(row=0,column=3,padx=5,pady=5)

win.mainloop()

 

posted @ 2017-06-21 13:59  疯陈演义  阅读(426)  评论(0编辑  收藏  举报