概述
from tkinter import *
import requests
import tkinter
app = Tk()
app.title('股票查询 深沪')
app.geometry('400x250')
v_text=StringVar()
v_name=StringVar()
name = Entry(app,textvariable=v_name,bd=5)
url='http://hq.sinajs.cn/list='
def go():
get_name=name.get()
url_new=url+get_name
res=requests.get(url_new).text
list=res.split(',')
v_text.set('当前查询股票:{}n今日开盘价:{}n昨日收盘价:{}n当前价格:{}n今日最高价:{}n今日最低价:{}n成交的股票数:{}n成交金额:{}n日期:{} {}'.format(str(list[0][21:]),list[1],list[2],list[3],list[4],list[5],list[8],list[9],list[30],list[31]))
def photo():
import io
# allows for image formats other than gif
from PIL import Image, ImageTk
try:
# Python2
import Tkinter as tk
from urllib2 import urlopen
except ImportError:
# Python3
import tkinter as tk
from urllib.request import urlopen
root = tk.Toplevel()
get_name=name.get()
url = "http://image.sinajs.cn/newchart/daily/n/{}.gif".format(get_name)
image_bytes = urlopen(url).read()
# internal data file
data_stream = io.BytesIO(image_bytes)
# open as a PIL image object
pil_image = Image.open(data_stream)
# optionally show image info
# get the size of the image
w, h = pil_image.size
# split off image file name
fname = url.split('/')[-1]
sf = "{} ({}x{})".format(fname, w, h)
root.title(sf)
# convert PIL image object to Tkinter PhotoImage object
tk_image = ImageTk.PhotoImage(pil_image)
# put the image on a typical widget
label = tk.Label(root, image=tk_image, bg='black')
label.pack(padx=5, pady=5)
root.mainloop()
def go_1():
import threading
t1=threading.Thread(target=photo)
t1.start()
name.pack()
go=Button(app,text='查询',command=go).pack()
photo_1=Button(app,text='图片',command=go_1).pack()
label_show=Label(app,textvariable=v_text).pack()
app.mainloop()
最后
以上就是无限羽毛为你收集整理的Python深沪股票查询(Tk可视化)的全部内容,希望文章能够帮你解决Python深沪股票查询(Tk可视化)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复