python设置tk退出_退出tkinter gui

 2023-09-07 阅读 29 评论 0

摘要:我知道有很多人都在同一个方向前进,但我找不到解决办法。很多线程即将关闭GUI,但仍在运行python代码,这是我不希望看到的。但请看下面我的问题:我目前使用的是python2.7和windows7。我正在开发一个程序来分析我从传感器读取的数据。在我完成我的p

我知道有很多人都在同一个方向前进,但我找不到解决办法。很多线程即将关闭GUI,但仍在运行python代码,这是我不希望看到的。但请看下面我的问题:

我目前使用的是python2.7和windows7。我正在开发一个程序来分析我从传感器读取的数据。在我完成我的python程序后,我用cx\u freeze冻结它,以便在没有python或没有matplotlib的pc上执行它。我的问题是我想添加一个退出按钮,关闭我的应用程序。问题是,我尝试了3种不同的可能性,见下文:import Tkinter

import numpy as np

import matplotlib

python中tkinter。from matplotlib import pyplot as plt

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg

import globals

import data2plot

#from __builtin__ import file

python pygame。globals.init()

def plot(x, aw,temperature,water):

#function to plot via matplotlib in the gui

#global file and if someone refresh before load data, default data is test.csv

file = "test"

python一个下划线和两个下划线、#Version1

def close_window():

sys.exit()

#Version2

def close_window2():

python readline。root.quit()

#Version3

def close_window3():

root.destroy()

# GUI

python opencv?root = Tkinter.Tk()

draw_button = Tkinter.Button(root, text="Quit", command = close_window)

draw_button.grid(row=1, column=2)

draw_button = Tkinter.Button(root, text="Quit2", command = close_window2)

draw_button.grid(row=1, column=3)

python编程?draw_button = Tkinter.Button(root, text="Quit3", command = close_window3)

draw_button.grid(row=1, column=4)

# init figure with the 3 different values and axes

fig = matplotlib.pyplot.figure()

canvas = FigureCanvasTkAgg(fig, master=root)

python web gui?canvas.get_tk_widget().grid(row=0,column=1)

toolbar = NavigationToolbar2TkAgg(canvas, root)

toolbar.grid(row=1,column=1)

#starts loop for the figure

root.mainloop()

python图形界面。我已经读到,通常我应该使用根。退出()选项。但是唯一能正常工作的按钮是第三个有错误的按钮根目录。销毁(). 问题是如果我使用第三个按钮,GUI正在关闭,但程序仍在运行?我是否也退出了主循环,但我认为我退出主循环时根。退出()? 在

另外两个按钮显示一条错误信息,程序在Windows7上崩溃了,但至少整个程序都关闭了。我也试着像一些人建议的那样根。退出没有括号,但根本不起作用。在

两个按钮的错误消息是:Fatal Python error: PyEval_RestoreThread: NULL tstate

This application has requested the Runtime to terminate it in an

unusual way. Please contact the application's support team for more

python web,information.

现在我的问题是如何确保我使用我的GUI,绘制一些东西等等,如果我按下quit按钮,GUI就会关闭,整个程序也会关闭?在

非常感谢!最大

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/16332.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息