首页 > 解决方案 > Python非阻塞通知/消息

问题描述

我有非常基本的简单要求,每次运行程序时,我都必须在运行 python 程序(3.X)时在 Windows 10 上显示非阻塞消息信息,但这需要两个主要条件

  1. 它应该是非阻塞的,这意味着我的 python 程序不会等待用户操作关闭或用户的任何其他操作

  2. 其次,程序执行时消息不应该消失。

我试过 tkinter、win10Toas、Plyer ...等。但未能成功实现这个简单的结果。

我在 tkinter 中的代码如下

import tkinter as tk

def show_message(type1, msg1, msg2, msg3):
    root = tk.Tk()
    if type1 == "L":
        h1 = "LOSS Notifications"
        tk.Label(root, text=msg1, fg="red", bg="yellow", font="Verdana 14 bold").pack()
        tk.Label(root, text=msg2, fg="red", bg="yellow", font="Verdana 14 bold").pack()
        tk.Label(root, text=msg3, fg="black", bg="orange", font="Verdana 14 bold").pack()
    elif type1 == "P":
        h1 = "Profit Notifications"
        tk.Label(root, text=msg1, fg="yellow", bg="blue", font="Verdana 14 bold").pack()
        tk.Label(root, text=msg2, fg="yellow", bg="blue", font="Verdana 14 bold").pack()
        tk.Label(root, text=msg3, fg="white", bg="green", font="Verdana 14 bold").pack()
    elif type1 == "N":
        h1 = "No Loss No Profit Notifications"
        tk.Label(root, text=msg1, fg="black", bg="white", font="Verdana 14 bold").pack()
        tk.Label(root, text=msg2, fg="black", bg="white", font="Verdana 14 bold").pack()
        tk.Label(root, text=msg3, fg="black", bg="white", font="Verdana 14 bold").pack()
    root.title(h1)
    root.bell()
    tk.mainloop()

此代码正在等待用户操作,没有此程序不会成功完成

你能帮忙吗?

标签: pythonpython-3.x

解决方案


推荐阅读