current position：Home>[Python development tool tkinterdiesigner]: example: develop stock monitoring alarm using Tkinter desinger
[Python development tool tkinterdiesigner]: example: develop stock monitoring alarm using Tkinter desinger
2022-01-29 13:52:55 【Huoyun cave red boy】
【Python Development tool -TKinterDesigner 】 ： Let's talk about it with examples ： Use TKinterDesigner Develop stock monitoring alarm
TKinterDesigner QQ Group ：100180960
This video tutorial is as follows ：https://www.bilibili.com/video/BV1LV411r7uc/
Use TkinterDesinger Develop stock monitoring alarm
Hello everyone , Spent a boring weekend , Many friends are waiting for Monday's A Let's open , Last week's continuous adjustment , So that many people's account profits have shrunk significantly , Even lose money , What should I do ？
I want to go to , Finally understand , People's emotions are A In front of the stock trend , It's just a piece of shit , Only powerful AI, Scientific analysis , To overcome fear and greed , Reach the other side of the profit .
Ha ha ha , Get down to business , This section , I teach you to use TKinterDesigner To develop a stock monitor , Help you lock in the bull stock in your heart , Do... At work “ I have a share in my hand , Nothing in my heart ！”.
good , Before we start , Let's prepare today's ingredients ：
open ：https://github.com/honghaier-game/TKinterDesigner, download V1.3.5.
then , Wash and clean hands , open TKinterDesigner, Create a new empty project .
Then let's design the function of the product ：
We hope to have a monitored stock pool , The stock code to be entered , The maximum and minimum price are set and put into the stock monitoring pool . After starting monitoring , Refresh per second , If the share price exceeds the ceiling or floor price , Will send SMS notification to our mobile phone number .
well , In the main form , Drag from the control panel Label,Button,Entry,TreeView, And modify the text and data , The designed interface is as follows ：
then , We need the view control corresponding to the stock pool TreeView Add a binding variable ：StockArray Array . Used to store stock information in the stock pool （ Stock code , Maximum and minimum price ）. well , So the interface is ready .
Now let's build a new one Python file , Named StockMonitor.py, Then we encapsulate the main functions we need here .
One . Stock information acquisition ： We use... Here tushare This financial Library , adopt pip install tushare You can install it , Then we can call get_realtime_quotes The interface monitors the stock in real time .
def getStockInfo(stock_code): df = ts.get_realtime_quotes(stock_code) # e = df[['code','name','time','price']] c = df[u'code'] n = df[u'name'] t = df[u'time'] p = df[u'price'] text = c + " " + n + " " + t + " " + p print(text) return df
Two . Send SMS service ： We use... Here twilio This foreign SMS service , After registration , Get a free trial phone number , Then bind and verify our mobile phone number , After passing, you can get the of the account SID And a TOKEN, stay twilio On our website , Detailed instructions for various development languages , I suggest you visit https://www.twilio.com/ Try .
account_sid = ""# Change to apply SID auth_token = ""# Change to apply TOKEN client = Client(account_sid, auth_token) smsText = "Stock:600050 Price 5.55" #from_ Change to the trial mobile phone number #to Change to the mobile phone number to receive the message , But remember +86 Oh client.messages.create(to="+8613488888888",from_="+13343784863",body=smsText)
These two functions , There are many introductions on the Internet , I won't explain them in detail here . With these two important Libraries , In fact, developing this monitoring is very simple .
Here are our custom classes StockMonitor.py Code for ：
import os import time import tushare as ts import pandas as pd import threading from twilio.rest import Client threadactive = True def getStockInfo(stock_code): df = ts.get_realtime_quotes(stock_code) # e = df[['code','name','time','price']] c = df[u'code'] n = df[u'name'] t = df[u'time'] p = df[u'price'] text = c + " " + n + " " + t + " " + p print(text) return df class StockMonitor: def __init__(self): self.StockArray =  self.TreeView = None self.PhoneNumber = None self.Run_Function = None def addStock(self,StockCode,MaxPrice,MinPrice): self.StockArray.append([StockCode,MaxPrice,MinPrice,False,False]) def SetMonitorInfo(self,TreeView,PhoneNumber): self.TreeView = TreeView self.PhoneNumber = PhoneNumber def StartMonitoring(self): account_sid = ""# Change to apply SID auth_token = ""# Change to apply TOKEN client = Client(account_sid, auth_token) all_items = self.TreeView.get_children() for item in all_items: self.TreeView.delete(item) for stock_code in self.StockArray: df = ts.get_realtime_quotes(stock_code) e = df[['code','name','price','time']] c = df[u'code'] n = df[u'name'] p = df[u'price'] t = df[u'time'] print(e) if float(p) > float(stock_code) : self.TreeView.insert('','end',values=(c,n,t,p,stock_code,stock_code," Over the limit ")) if stock_code == False: # smsText = " Your stock "+n+"("+c+") The set ceiling price has been exceeded "+ stock_code + ", Current price "+p+", Please pay attention to !" smsText = "Stock:"+"("+c+") Price:"+p #from_ Change to the trial mobile phone number client.messages.create(to=self.PhoneNumber,from_="+13343784863",body=smsText) stock_code = True elif float(p) < float(stock_code): self.TreeView.insert('','end',values=(c,n,t,p,stock_code,stock_code," Below the lower limit ")) if stock_code == False: # smsText = " Your stock "+n+"("+c+") The price is lower than the set lower limit "+ stock_code + ", Current price "+p+", Please pay attention to !" smsText = "Stock:"+"("+c+") Price:"+p print(smsText) #from_ Change to the trial mobile phone number client.messages.create(to=self.PhoneNumber,from_="+13343784863",body=smsText) stock_code = True else: self.TreeView.insert('','end',values=(c,n,t,p,stock_code,stock_code," Smooth fluctuations ")) self.Run_Function = self.TreeView.after(1000, self.StartMonitoring) def StopMonitoring(self): self.TreeView.after_cancel(self.Run_Function) self.StockArray = 
We are in this class , adopt addStock Add stock information to the monitoring pool , stay SetMonitorInfo Corresponding to the stock pool TreeView And the phone number of the alarm receiver .
When we press the start monitoring button on the interface , Call StartMonitoring, At the same time, change the button text to “ Stop monitoring ”, Press again , Then stop monitoring and restore the text to “ Start the monitoring ”.
With this class code , We go back to TKinterDesigner. We are “ Increase stock ” Right click on the button , eject “ Event response ”, And then to "Command" Add function code ：
def Button_4_onCommand(className,widgetName): StockCode = Fun.GetUIText(className,"Entry_3") StockInfo = StockMonitor.getStockInfo(StockCode) StockCode = StockInfo[u'code'] StockName = StockInfo[u'name'] StockTime = StockInfo[u'time'] StockPrice = StockInfo[u'price'] MaxPrice = Fun.GetUIText(className,"Entry_10") MinPrice =Fun.GetUIText(className,"Entry_12") TreeView13 = Fun.GetUIEle(className,"TreeView_13") TreeView13 .insert('','end',values=(StockCode,StockName,StockTime,StockPrice,MinPrice,MaxPrice)) StockArray = Fun.GetUIData(className,"TreeView_13","StockArray") StockArray.append([StockCode,MaxPrice,MinPrice])
This function , The main purpose is to display the filled stock information to TreeView And the bound array variables put into it . Need here import StockMonitor Oh .
The way to use is “ Start the monitoring ” Button code , Yes StockMonitor Class instantiation in , And call StartMonitoring Function to monitor .
StockMonitorInst = None def Button_6_onCommand(className,widgetName): global StockMonitorInst BtnText = Fun.GetUIText(className,widgetName) if BtnText == " Start the monitoring ": if StockMonitorInst == None: StockMonitorInst = StockMonitor.StockMonitor() StockArray = Fun.GetUIData(className,"TreeView_13","StockArray") for stockcode in StockArray: StockMonitorInst.addStock(stockcode,stockcode,stockcode) TreeView = Fun.GetUIEle(className,"TreeView_13") PhoneNumber=Fun.GetUIText(className,"Entry_17") StockMonitorInst.SetMonitorInfo(TreeView,PhoneNumber) StockMonitorInst.StartMonitoring() Fun.SetUIText(className,widgetName," Stop monitoring ") else: StockMonitorInst.StopMonitoring() Fun.SetUIText(className,widgetName," Start the monitoring ")
If monitoring is not required , Click the button again .
author[Huoyun cave red boy],Please bring the original link to reprint, thank you.
The sidebar is recommended
- [Python introduction project] use Python to generate QR code
- Quickly build Django blog based on function calculation
- Python interface test unittest usage details
- Implementation of top-level design pattern in Python
- You can easily get started with Excel. Python data analysis package pandas (VII): breakdown
- Python simulation random coin toss (non optimized version)
- Using linear systems in python with scipy.linalg
- Together with Python to do a license plate automatic recognition system, fun and practical!
- Using linear systems in python with scipy.linalg
- Fast power modulus Python implementation of large numbers
guess what you like
Quickly build Django blog based on function calculation
You can easily get started with Excel pandas (I): filtering function
You can easily get started with Excel. Python data analysis package pandas (II): advanced filtering (I)
You can easily get started with Excel. Python data analysis package pandas (2): advanced filtering (2)
How does Python correctly call jar package encryption to get the encrypted value?
Python 3 interview question: give an array. If there is 0 in the array, add a 0 after 0, and the overall array length remains the same
Python simple Snake game (single player mode)
Using linear systems in python with scipy.linalg
Python executes functions and even code through strings! Come and understand the operation of such a top!
Decoding the verification code of Taobao slider with Python + selenium, the road of information security
- [Python introduction project] use Python to generate QR code
- Vanessa basks in her photos and gets caught up in the golden python. There are highlights in the accompanying text. She can't forget Kobe after all
- [windows] Python installation pyteseract
- [introduction to Python project] create bar chart animation in Python
- Python series tutorials 116
- Practical series 1 ️⃣ Wechat applet automatic testing practice (with Python source code)
- Python Basics: do you know how to use lists?
- [common links of Python & Python]
- [Python development tool Tkinter designer]: Lecture 1: introduction to the basic functions of Tkinter Designer
- [introduction to Python tutorial] use Python 3 to teach you how to extract any HTML main content
- Python socket implements UDP server and client
- Python socket implements TCP server and client
- leetcode 1974. Minimum Time to Type Word Using Special Typewriter（python）
- The mobile phone uses Python to operate picture files
- [learning notes] Python exception handling try except...
- Two methods of using pandas to read poorly structured excel. You're welcome to take them away
- Python sum (): the summation method of Python
- Using Python to realize multitasking process