Python在M上的消息窗口

2024-04-16 16:11:50 发布

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

我正在使用macos,用于python程序。如果条件为真,我想显示一个消息框。有人能告诉我如何为macOS创建一个Python消息框,当条件为TrueFalse时可以调用它吗?你知道吗

我试过了

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)

但是这个,我不知道如何根据情况打电话。你知道吗


Tags: import程序falsetrue消息messagewithdisplay
1条回答
网友
1楼 · 发布于 2024-04-16 16:11:50

也许这能帮上忙

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.")

相关问题 更多 >