How to create an alert box without using Tkinter?

只愿长相守 提交于 2020-01-17 18:10:19

问题


I need to create a message box in python without using python Tkinter library so that I can use that before using exit() function this will display the message and answer as soon as user presses okay, user gets out of program.


回答1:


Here's one way to do it with Windows' msg command. The code is based on @ErykSun's comment under the question Can't execute msg (and other) Windows commands via subprocess.

import os
import subprocess

sysroot = os.environ['SystemRoot']
sysnative = (os.path.join(sysroot, 'SysNative')
                if os.path.exists(os.path.join(sysroot, 'SysNative'))
             else
                os.path.join(sysroot, 'System32'))
msgexe_path = os.path.join(sysnative, 'msg.exe')
subprocess.run([msgexe_path, '*', 'ALL YOUR BASE ARE WHERE BELONG TO US.'])



来源:https://stackoverflow.com/questions/59704480/how-to-create-an-alert-box-without-using-tkinter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!