# -*- coding:utf-8 -*-
import pymysql
import threading
import time
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
from matplotlib.patches import Circle
fig, ax = plt.subplots()
r=0
#python连接数据库操作
def t1():
global r
conn = pymysql.connect(
user="root",
password="123",
port=3306,
host="127.0.0.1", #本地数据库 等同于localhost
db="1", #数据库名
charset="utf8"
)
cur = conn.cursor() # 获取对应的操作游标
#获得数据库中的第一条数据
query = "select `range` from 00f92acd_detail where mac='ec:3d:fd:f9:2a:cd' GROUP BY master_id ORDER BY master_id DESC LIMIT 0,1 "
cur.execute(query)
r = cur.fetchone()
r = r[0]
r = float(r)
def animat(i):
global r
plt.cla()
cir = Circle(xy=(0.5, 0.5), radius=r / 100., alpha=0.5, fill=0)
ax.add_patch(cir)
#对函数def_t1()每一秒执行一次
def t2():
ani = animation.FuncAnimation(fig=fig, func=animat, frames=10000, interval=1000, blit=False)
while 1:
t1()
time.sleep(1)
if __name__ == '__main__':
t = threading.Thread(target=t2)
t.start()
plt.show()
# 此处写你主线程要处理的事情.....
t.join()