是否可以在python中生成类似于JavaScript的警报("消息")的警报,并将应用程序作为守护程序运行.
这将在Windows中运行,很可能是XP但2000和Vista也是非常真实的可能性.
更新:
这是为了在后台运行并在满足某些条件时提醒用户,我认为提醒用户的最简单方法是生成弹出窗口,因为它需要立即处理,以及其他选项例如记录或发送电子邮件都不够有效.
小智 54
那这个呢:
import win32api
win32api.MessageBox(0, 'hello', 'title')
Run Code Online (Sandbox Code Playgroud)
另外:
win32api.MessageBox(0, 'hello', 'title', 0x00001000)
Run Code Online (Sandbox Code Playgroud)
将使该框显示在其他窗口的顶部,用于紧急消息.有关其他选项,请参阅MessageBox函数.
Mat*_*ord 14
对于我们这些寻找不与 Windows 接口且独立于平台的纯 Python 选项的人来说,我选择了以下网站上列出的选项:
https://pythonspot.com/tk-message-box/
# Python 3.x code
# Imports
import tkinter
from tkinter import messagebox
# This code is to hide the main tkinter window
root = tkinter.Tk()
root.withdraw()
# Message Box
messagebox.showinfo("Title", "Message")
Run Code Online (Sandbox Code Playgroud)
您可以选择为不同的场景显示各种类型的消息框选项:
根据我下面的评论编辑代码
小智 6
您可以使用PyAutoGui制作警报框首先使用pip安装pyautogui:
pip install pyautogui
Run Code Online (Sandbox Code Playgroud)
然后在 python 中输入:
pip install pyautogui
Run Code Online (Sandbox Code Playgroud)
以下是从 Javascript 中窃取的更多消息框:
confirm()prompt()password()
使用文本输入,但键入的字符将显示为*