关闭tkinter窗口时,python程序不会结束 您所在的位置:网站首页 tkinter窗口关闭 关闭tkinter窗口时,python程序不会结束

关闭tkinter窗口时,python程序不会结束

2023-01-04 04:52| 来源: 网络整理| 查看: 265

我正在做一个项目,使示波器喜欢图形用户界面。虽然图形用户界面还没有准备好,但是我有一个问题,当我关闭TKinter窗口时,程序没有被关闭。它仍然在python shell中运行。我想这可能是关闭tkinter相关程序的方法。但我发现,在某些程序中,只要关闭tkinter窗口,就会杀死程序。在我的例子中,即使在关闭tkinter窗口之后,程序仍在python shell中运行。我把我的代码放在这里,请看看问题出在哪里?

from tkinter import * from matplotlib import pyplot as plt import matplotlib.animation as animation from matplotlib import style from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg import numpy as np root = Tk() root.geometry("800x500+100+100") root.title('root window') frame = Frame(root, borderwidth=1,bg="#0DBDAB") ## This is the frame in which plot will be shown frame.place(relx=1.0/3,rely=0.5, anchor="center", relwidth=0.60,relheight=0.8) xar = [0] yar = [0] k=0.2 ### This is just a constant to make plot smoother style.use('ggplot') fig = plt.figure(figsize=(20,20), dpi=100) ax1 = fig.add_subplot(1, 1, 1) ax1.set_ylim(-1, 1) line, = ax1.plot(xar, yar, 'r') ## It will not plot regularly instead add line for new data def animate(i): ax1.set_xlim(left=max(0,i-20), right=i+1) yar.append(np.sin(i*k)) xar.append(i) line.set_data(xar,yar) return line, plotcanvas = FigureCanvasTkAgg(fig, frame) plotcanvas.get_tk_widget().pack(side=BOTTOM,fill=BOTH,expand=True) ani = animation.FuncAnimation(fig, animate, interval=1000, blit=False) root.mainloop()


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有