Simple stock data query UI through tkinter and tushare

Simple stock data query UI through tkinter and tushare

#tushare Introduction
Tushare is a free, open source Python financial data interface package. It mainly realizes the process of financial data such as stocks from data collection, cleaning and processing
to
data storage, which can provide financial analysts with fast, clean, and diverse data that is easy to analyze, greatly reducing the workload of data acquisition, so that They are more focused on the research and implementation of strategies and models.

Code

__author__ = 'Yuan'

"""使用前先安装tushare"""

import tkinter
import tushare
from tkinter import messagebox
import multiprocessing

class SearchStock:
    stockNumber = '002056'
    location = None

    def IDSet(self, object):
        self.stockNumber = str(object.get())
        print(self.stockNumber)

    def locationSet(self, object):
        self.location = str(object.get())
        print(self.location)

def searchStock(self):
        try :
            data = tushare.get_hist_data(code =self.stockNumber)
            print(data)
            try :
                data.to_excel(self.location)
                print('successful')
            except :
                tc1 = messagebox.showinfo(title='error', message='找不到存储位置')
                print(tc1)
        except :
            str = messagebox.showinfo(title='error', message='股票代码错误')
            print(str)
class App:
    def __init__(self,window,Stock):
        window.title('StockSearch')
        window.geometry('1000x600')
        var = tkinter.StringVar()
        var2 = tkinter.StringVar()
        label1 = tkinter.Label(window, text='股票代码')
        label1.pack()
        stock = tkinter.Entry(window,textvariable=var)
        stock.pack()
        stockButton = tkinter.Button(window, text='提交', font=('Arial', 12), width=10, height=1,
                           command=lambda: Stock.IDSet(stock))
        stockButton.pack()
        label1 = tkinter.Label(window, text='存储位置')
        label1.pack()
        save = tkinter.Entry(window,textvariable=var2)
        save.pack()
        saveButton = tkinter.Button(window, text='提交', font=('Arial', 12), width=10, height=1,
                           command=lambda: Stock.locationSet(save))
        saveButton.pack()
        print(stock['state'])
        # a = var.get()
        # b = var2.get()
        # print(a)
        # print(b)
        # Stock.IDSet(object = var)
        # Stock.locationSet(object = var2)
        b = tkinter.Button(window, text='查询', font=('Arial', 12), width=10, height=1, command=lambda: searchStock(Stock))
        b.pack()

def main():
    window = tkinter.Tk()
    Stock = SearchStock()
    APP = App(window, Stock)
    window.mainloop()


if __name__ == '__main__' :
    multiprocessing.freeze_support()
    main()
Published 7 original articles · won 11 · views 259

Guess you like

Origin blog.csdn.net/weixin_43165512/article/details/105332540