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

 1 #/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 '''
 4 @author="livermorium116"
 5 为了绕开公司内网而开发的
 6 股票实时显示小程序
 7 (1)程序基于QT5,pyQt5以及tushare库
 8 (2)程序实时地简易显示时间、股票代码、盈亏数额
 9 (3)使用方法:在终端直接运行python filename
10 '''
11 
12 
13 import sys
14 from PyQt5.QtWidgets import *
15 from PyQt5.QtGui import *
16 from PyQt5.QtCore import *
17 import tushare as ts
18 import numpy as np
19 import time
20 
21 
22 
23 
24 
25 class Example(QWidget):
26     def __init__(self):
27         super(Example, self).__init__()
28     
29 
30         self.initUI()
31         self.str1=""
32         self.Flag=0
33         self.cost=19.57###把它修改成你的股票买入价格
34 
35     def initUI(self):
36         QToolTip.setFont(QFont('SansSerif', 10))
37 
38         self.setToolTip('This is a <b>QWidget</b> widget')
39         self.label=QLabel(self)
40         self.label.setText("Begin.....")
41         self.label.setFont(QFont("SansSerif",20))
42 
43         self.timer = QTimer()
44         self.timer.setInterval(1000)
45         self.timer.start()
46         self.timer.timeout.connect(self.onTimerOut)
47 
48 
49 
50         self.setGeometry(300, 300, 380, 28)
51         self.setWindowTitle('My Stock Price Indicator')
52         self.show()
53 
54 
55 
56 
57     def onTimerOut(self):
58 
59         df = ts.get_realtime_quotes("600030")##把它修改成你要购买的股票价格
60         x=df["time"].to_dict()
61         self.str1=str(x[0])
62         
63 
64         x=df["price"].to_dict()
65         self.str1 = self.str1 + "  " + (x[0])
66 
67         sP=float(x[0])
68         x=(sP-self.cost)*400
69         self.str1=self.str1+ "  " + str(x)
70         if x > 0 :
71             pe = QPalette()
72             pe.setColor(QPalette.WindowText, Qt.red)  # 设置字体颜色,红色表示盈利
73             self.label.setPalette(pe)
74 
75 
76 
77         self.label.setText(self.str1)
78         self.label.setVisible(self.Flag)
79         self.Flag=1-self.Flag
80         ##time.sleep(3)
81 
82 
83 
84 
85 if __name__ == '__main__':
86     app = QApplication(sys.argv)
87     ex = Example()
88     sys.exit(app.exec_())

 

转载于:https://www.cnblogs.com/milliard/p/7877840.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值