PyZenity is an easy to use interface to Zenity for Python.
Zenity is normally called from scripts by invoking it with a multitude of command line parameters that it uses to construct its interfaces. This module hides the details of invoking the command and presents simple API functions like:
cancel = Question(‘Should I cancel the operation?’)
Each function takes optional kwargs parameters. This is to allow the use of general Zenity parameters such as:
title - Set the dialog title window_icon - Set the window icon ok_label - Set the text for the Ok label cancel_label - Set the text for the Cancel label height - Set the height width - Set the width timeout - Set the dialog timeout in seconds
Prompt the user for a date.
This will raise a Zenity Calendar Dialog for the user to pick a date. It will return a datetime.date object with the date or None if the user hit cancel.
text - Text to be displayed in the calendar dialog. selected - A datetime.date object that will be the pre-selected date. kwargs - Optional command line parameters for Zenity such as height,
width, etc.
Prompt the user for a filename.
This will raise a Zenity File Selection Dialog. It will return a list with the selected files or None if the user hit cancel.
multiple - True to allow the user to select multiple files. sep - Token to use as the path separator when parsing Zenity’s return
string.
Prompt the user for a directory.
This will raise a Zenity Directory Selection Dialog. It will return a list with the selected directories or None if the user hit cancel.
multiple - True to allow the user to select multiple directories. selected - Path to the directory to be selected on startup. sep - Token to use as the path separator when parsing Zenity’s return
string.
Prompt the user for a filename to save as.
This will raise a Zenity Save As Dialog. It will return the name to save a file as or None if the user hit cancel.
default - The default name that should appear in the save as dialog. kwargs - Optional command line parameters for Zenity such as height,
width, etc.
Put an icon in the notification area.
This will put an icon in the notification area and return when the user clicks on it.
text - The tooltip that will show when the user hovers over it. window_icon - The stock icon (“question”, “info”, “warning”, “error”) or
path to the icon to show.
Present a list of items to select.
This will raise a Zenity List Dialog populated with the colomns and rows specified and return either the cell or row that was selected or None if the user hit cancel.
column_names - A tuple or list containing the names of the columns. title - The title of the dialog box. boolstyle - Whether the first columns should be a bool option (“checklist”,
“radiolist”) or None if it should be a text field.
editable - True if the user can edit the cells. select_col - The column number of the selected cell to return or “ALL” to
return the entire row.
Show an error message dialog to the user.
This will raise a Zenity Error Dialog with a description of the error.
text - A description of the error. kwargs - Optional command line parameters for Zenity such as height,
width, etc.
Show an info message dialog to the user.
This will raise a Zenity Info Dialog displaying some information.
text - The information to present to the user. kwargs - Optional command line parameters for Zenity such as height,
width, etc.
Ask the user a question.
This will raise a Zenity Question Dialog that will present the user with an OK/Cancel dialog box. It returns True if the user clicked OK; False on Cancel.
text - The question to ask. kwargs - Optional command line parameters for Zenity such as height,
width, etc.
Show a warning message dialog to the user.
This will raise a Zenity Warning Dialog with a description of the warning. It returns True if the user clicked OK; False on cancel.
text - A description of the warning. kwargs - Optional command line parameters for Zenity such as height,
width, etc.
Show a progress dialog to the user.
This will raise a Zenity Progress Dialog. It returns a callback that accepts two arguments. The first is a numeric value of the percent complete. The second is a message about the progress.
text - The initial message about the progress. percentage - The initial percentage to set the progress bar to. auto_close - True if the dialog should close automatically if it reaches
100%.
pulsate - True is the status should pulsate instead of progress. kwargs - Optional command line parameters for Zenity such as height,
width, etc.
Get some text from the user.
This will raise a Zenity Text Entry Dialog. It returns the text the user entered or None if the user hit cancel.
text - A description of the text to enter. entry_text - The initial value of the text entry box. password - True if text entered should be hidden by stars. kwargs - Optional command line parameters for Zenity such as height,
width, etc.
Show the text of a file to the user.
This will raise a Zenity Text Information Dialog presenting the user with the contents of a file. It returns the contents of the text box.
filename - The path to the file to show. editable - True if the text should be editable. kwargs - Optional command line parameters for Zenity such as height,
width, etc.