Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use an alert dialog with Python in linux?

My question is similar to this question, but I'm using Xubuntu, so the win32 api is obviously not available. Is there some alternative I can use?

I just need to have a simple window pop up with a message, from a python script.

like image 311
Michael Hoffmann Avatar asked Aug 30 '15 15:08

Michael Hoffmann


People also ask

How do you display alerts in Python?

The warn() function defined in the ' warning ' module is used to show warning messages. The warning module is actually a subclass of Exception which is a built-in class in Python.

How do I display a dialog box in Python?

The tkMessageBox module is used to display message boxes in your applications. This module provides a number of functions that you can use to display an appropriate message. Some of these functions are showinfo, showwarning, showerror, askquestion, askokcancel, askyesno, and askretryignore.


1 Answers

To create a notification rather than a dialog box that needs to be dismissed, you can use notify-send as shown below. This also does not require installing python-tk or other packages.

import subprocess
subprocess.run(["/usr/bin/notify-send", "--icon=error", "This is your error message ..."])

See the man page for more options.

like image 180
bitinerant Avatar answered Oct 17 '22 08:10

bitinerant