1. 程式人生 > >基於pyQt5開發的股價顯示器(原創)

基於pyQt5開發的股價顯示器(原創)

star ets 時間 class 修改 imp price 內網 pre

 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_())

基於pyQt5開發的股價顯示器(原創)