基于pyQt5开发的股价显示器(原创)

 #/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@author="livermorium116"
为了绕开公司内网而开发的
股票实时显示小程序
(1)程序基于QT5,pyQt5以及tushare库
(2)程序实时地简易显示时间、股票代码、盈亏数额
(3)使用方法:在终端直接运行python filename
''' import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import tushare as ts
import numpy as np
import time class Example(QWidget):
def __init__(self):
super(Example, self).__init__() self.initUI()
self.str1=""
self.Flag=0
self.cost=19.57###把它修改成你的股票买入价格 def initUI(self):
QToolTip.setFont(QFont('SansSerif', 10)) self.setToolTip('This is a <b>QWidget</b> widget')
self.label=QLabel(self)
self.label.setText("Begin.....")
self.label.setFont(QFont("SansSerif",20)) self.timer = QTimer()
self.timer.setInterval(1000)
self.timer.start()
self.timer.timeout.connect(self.onTimerOut) self.setGeometry(300, 300, 380, 28)
self.setWindowTitle('My Stock Price Indicator')
self.show() def onTimerOut(self): df = ts.get_realtime_quotes("")##把它修改成你要购买的股票价格
x=df["time"].to_dict()
self.str1=str(x[0]) x=df["price"].to_dict()
self.str1 = self.str1 + " " + (x[0]) sP=float(x[0])
x=(sP-self.cost)*400
self.str1=self.str1+ " " + str(x)
if x > 0 :
pe = QPalette()
pe.setColor(QPalette.WindowText, Qt.red) # 设置字体颜色,红色表示盈利
self.label.setPalette(pe) self.label.setText(self.str1)
self.label.setVisible(self.Flag)
self.Flag=1-self.Flag
##time.sleep(3) if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
上一篇:Kafka的安装和部署及测试


下一篇:Nginx+Tomcat+memcached高可用会话保持