{"id":320319,"date":"2021-02-05T10:40:12","date_gmt":"2021-02-05T02:40:12","guid":{"rendered":"http:\/\/4563.org\/?p=320319"},"modified":"2021-02-05T10:40:12","modified_gmt":"2021-02-05T02:40:12","slug":"%e5%a6%82%e4%bd%95%e6%9a%82%e5%81%9c%e4%b8%80%e4%b8%aa%e5%87%bd%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=320319","title":{"rendered":"\u5982\u4f55\u6682\u505c\u4e00\u4e2a\u51fd\u6570\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5982\u4f55\u6682\u505c\u4e00\u4e2a\u51fd\u6570\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yellowtail <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4ee3\u7801\u5728 jupyternotebook \u91cc\u5199\u7684\uff0c\u5947\u602a\u7684\u662f\u5728\u529e\u516c\u5ba4\u80fd\u7528\uff0c\u5bb6\u91cc\u4e0d\u80fd\u7528\u4e86&#8230; \u6574\u4e2a\u529f\u80fd\u5c31\u662f\u7528 apscheduler \u5b9a\u65f6\u8fd0\u884c\u751f\u6210\u968f\u673a\u6570\u7136\u540e\u5728 tkinter \u91cc\u53ef\u89c6\u5316 \u73b0\u5728\u60f3\u4fdd\u7559\u539f\u4ee3\u7801\u91cc root.after \u529f\u80fd\uff08\u56e0\u4e3a\u76f4\u63a5\u7528 root.after\uff0c\u6309\u73b0\u5728\u505a\u6cd5\u5b9a\u65f6\u51fd\u6570\u5c31\u6ca1\u7528\u4e86\uff0c\u56e0\u4e3a root.after \u662f\u5faa\u73af\u7684) \u611f\u89c9\u53ef\u4ee5\u7528\u9501\u7684\u65b9\u6cd5\uff0c\u4f46\u662f\u6c34\u5e73\u6349\u6025\u5199\u4e0d\u51fa\u6765\uff0c\u6c42\u6307\u6559\u3002\u3002<\/p>\n<p>&#8221;&#8217; import datetime from apscheduler.schedulers.background import BackgroundScheduler import random import numpy as np from tkinter import * from tkinter import messagebox import matplotlib.pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg import multiprocessing from threading import Thread import time<\/p>\n<pre><code>root = Tk() root.title(\"tkinter + Matplotlib\") root.geometry('700x750') plt.rcParams['axes.unicode_minus']=False plt.rcParams['font.sans-serif'] = ['SimHei']  fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) ax2 = ax1.twinx()  ax1.set_title('\u968f\u673a\u751f\u6210\u6570')  ax1.set_ylim() ax2.set_ylim()  ax1.set_xlim(0, 200) ax2.set_xlim(0, 200)  ax1.grid(True)  ax1.set_xlabel(\"time\") ax1.set_ylabel(\"\u968f\u673a\u6570 1\") ax2.set_ylabel(\"\u968f\u673a\u6570 2\")  canvas = FigureCanvasTkAgg(fig, master=root) canvas.draw()  canvas.get_tk_widget().pack()  x = 0 ran1 = [] ran2 = [] times = []  def drawImg():      global ran1     global ran2     global times     global x     global ax1     global ax2      v1 = float(random.randint(-5, 5))     r1 = float(random.randint(-10, 10))     ran1.append(v1)     ran2.append(r1)     times.append(x)     x += 1      ax1.clear()     ax2.clear()     ax1.axes.set_ylim(min(ran1)-5, 5+max(ran1))     ax2.axes.set_ylim(min(ran2)-5, 5+max(ran2))     ax1.axes.set_xlim(x-200+200, x+20)     ax2.axes.set_xlim(x-200+20, x+20)      ax1.plot(times, ran1,'y')     ax2.plot(times, ran2,'r')     canvas.draw()     #global afterHandler     #afterHandler = root.after(10, drawImg)     #print(datetime.datetime.now())  def sub_task():     drawImg()  def task_(time):     def task__():         temp = BackgroundScheduler()         temp.add_job(sub_task,'interval',seconds = 1,end_date =str(datetime.datetime.now())[:17]+time)         temp.start()     return task__  sche_fn = BackgroundScheduler() sche_fn.add_job(task_('25'),'cron',day_of_week = 'mon-fri',hour = '*',minute = '*',second = '0' ) sche_fn.start() sche_an = BackgroundScheduler() sche_an.add_job(task_('55'),'cron',day_of_week = 'mon-fri',hour = '*',minute = '*',second = '30' ) sche_an.start()    def on_closing():     sche_an.shutdown()     sche_fn.shutdown()     #root.after_cancel(afterHandler)     answer = messagebox.askokcancel(\"\u9000\u51fa\", \"\u786e\u5b9a\u9000\u51fa\u5417?\")     if answer:         plt.close('all')         root.destroy()     else:         root.after(1000, drawImg)   root.protocol(\"WM_DELETE_WINDOW\", on_closing) root.mainloop() <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5095666\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : shniubobo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u8981\u6682\u505c\u51fd\u6570\u7684\u8bdd\u53ef\u4ee5\u8003\u8651`yield`\u3002\u51fd\u6570\u91cc\u6709`yield`\u7684\u8bdd\uff0c\u8c03\u7528\u51fd\u6570\u4f1a\u8fd4\u56de\u4e00\u4e2a\u751f\u6210\u5668\u3002`next(\u751f\u6210\u5668)`\u4f1a\u8ba9\u51fd\u6570\u8fd0\u884c\u5230`yield`\u5904\u4e2d\u65ad\uff0c\u5e76\u8fd4\u56de`yield`\u7684\u503c\uff0c\u8fd9\u6837\u5c31\u76f8\u5f53\u4e8e\u6682\u505c\u4e86\u51fd\u6570\u3002\u6709\u5173`yield`\u89c1 python \u6587\u6863\u8bed\u8a00\u53c2\u8003\u90e8\u5206\uff0c`next`\u89c1\u6807\u51c6\u5e93\u53c2\u8003\u90e8\u5206\u3002<br \/>\u8fd8\u6709\u5c31\u662f\u8003\u8651\u534f\u7a0b\u4e86\uff0c\u89c1\u6807\u51c6\u5e93\u7684`asyncio`\u3002python \u65e9\u671f\u7684\u534f\u7a0b\u5176\u5b9e\u4e5f\u662f\u57fa\u4e8e\u4e0a\u9762\u8bf4\u7684\u751f\u6210\u5668\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u6682\u505c\u4e00\u4e2a\u51fd\u6570\uff1f \u8cc7\u6df1\u5927\u4f6c : &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/320319"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=320319"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/320319\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=320319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=320319"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=320319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}