Python - 每次循环产生输出时通知用户 Tkinter?

Python - notify user every time a loop yields an output Tkinter?

我每 5 分钟接收一次 API 数据和 运行 一个 Python 代码来检查传入数据是否满足特定条件。数据采用 JSON 格式,但我将其转换为数据框并在那里执行检查。 如果其中一项检查产生命中,我希望收到通知。我想找到一种快速且节省资源的方式让 Python 通知我。

用一行文本生成 window(最好是带有音频声音)的最有效(简约)代码是什么,例如"Condition1/2/3/4 fulfilled, timestamp, string"

感谢您的帮助

你可以做比这更简单的事情来帮助你在收到东西时通知你。您可以使用 os 库在文件被打印时打开文件。假设您使用 data.to_excel。之后,您可以打开它。 为此,您只需导入 os,函数为 os.system(path_of_excel_file)。在路径中,您必须小心并使用反斜杠来表示空格或其他特殊字符。

使用 messagebox 可能非常 easy.A 最小示例:

from tkinter import messagebox
import time
import tkinter as tk

root = tk.Tk()
info = "what"
root.withdraw()
if condition:
    messagebox.showinfo("title",f"Condition-1 fulfilled time:{time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime())} \n info:{info}")

如果条件是True,它会显示一个小window(它会播放默认的系统声音,不需要使用winsound.Beep())。