首页 > 解决方案 > Mac 上 Python 的消息窗口

问题描述

我正在使用 MAC OS,用于 python 程序。如果条件为真,我想显示一个消息框。True有人可以告诉我如何为 macOS 创建一个 Python 消息框,当条件为or时可以调用它False

我试过了

import subprocess

applescript = """
display dialog "Some message goes here..." ¬
with title "This is a pop-up window" ¬
with icon caution ¬buttons {"OK"}"""

subprocess.call("osascript -e '{}'".format(applescript), shell=True)

但是这个,我不知道如何根据条件调用。

标签: pythonmacosmessagebox

解决方案


可能这可以帮助

import Tkinter
import tkMessageBox

# An error box
if(condition)
    tkMessageBox.showerror("Error","No disk space left on device")

# A warning box 
if(condition)
    tkMessageBox.showwarning("Warning","Could not start 
service")

# An information box
if(condition)
    tkMessageBox.showinfo("Information","Created in Python.")

推荐阅读