Python非阻塞通知/messag

2024-04-25 23:25:14 发布

您现在位置:Python中文网/ 问答频道 /正文

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

  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()

此代码正在等待用户操作,没有此程序就无法成功完成

你能帮忙吗


Tags: textrooth1labelpacktkbgfont