easygraphics.dialog package

An easy-to-use dialogs library.

You can use it to create and show dialogs.

Based on code from EasyGUI_Qt(https://github.com/aroberge/easygui_qt/). The original EasyGUI-Qt library won’t work properly with EasyGraphics. So use this library instead.

A simple example:

>>> from easygraphics.dialog import *
>>> name=get_string("name")
>>> show_message("Your name is "+name)

Functions

easygraphics.dialog.set_dialog_font_size(size: int)

Set font size of the dialogs.

Parameters:size – font size
>>> from easygraphics.dialog import *
>>> set_dialog_font_size(18)
>>> show_message("font setted!")
easygraphics.dialog.show_message(message: str = 'Message', title: str = 'Title')

Simple message box.

Parameters:
  • message – message string
  • title – window title
>>> from easygraphics.dialog import *
>>> show_message()
../_images/show_message.png
easygraphics.dialog.show_text(title: str = 'Title', text: str = '', width: int = 720, height: int = 450)

Displays some text in a window.

Parameters:
  • title – the window title
  • text – a string to display in the window.
  • width – width of the dialog window
  • height – height of the dialog window
>>> from easygraphics.dialog import *
>>> show_text("Hello","Hello world!")
../_images/show_text.png
easygraphics.dialog.show_code(title: str = 'Title', code: str = '', width: int = 720, height: int = 450)

Displays some text in a window, in a monospace font.

Parameters:
  • title – the window title
  • code – a string to display in the window.
  • width – width of the dialog window
  • height – height of the dialog window
../_images/show_code.png
easygraphics.dialog.show_file(file_name: str = None, title: str = 'Title', file_type: str = 'text', width: int = 720, height: int = 450)

Displays a file in a window. While it looks as though the file can be edited, the only changes that happened are in the window and nothing can be saved.

Parameters:
  • title – the window title
  • file_name – the file name, (path) relative to the calling program
  • file_type – possible values: text, code, html, python.
  • width – width of the dialog window
  • height – height of the dialog window

By default, file_type is assumed to be text; if set to code, the content is displayed with a monospace font and, if set to python, some code highlighting is done. If the file_type is html, it is processed assuming it follows html syntax.

Note: a better Python code hightlighter would be most welcome!

>>> from easygraphics.dialog import *
>>> show_file()
../_images/show_file.png
easygraphics.dialog.show_objects(datas: Sequence[T_co], fields: Sequence[str] = None, field_names: Sequence[str] = None, title: str = 'Title', width: int = 720, height: int = 450, enable_sorting=False)

Displays list of objects in a table

>>> from easygraphics.dialog import *
>>> class Person:
>>>     def __init__(self,name,age,sex):
>>>         self.name=name
>>>         self.age = age
>>>         self.sex = sex
>>> objs = [Person("Jack", 22, "M"), Person("Micheal", 40, "F"), Person("David", 24, "M")]
>>> show_objects(title="peoples",datas=objs,fields=["name","age","sex"],field_names=["NAME","AGE","SEX"])
../_images/show_objects.png
Parameters:
  • datas – the object list to show
  • fields – fields to show of the object
  • field_names – the field names displayed on the table header
  • title – title of the dialog window
  • width – width of the dialog window
  • height – height of the dialog window
  • enable_sorting – if data can be sorted by clicking the column name
easygraphics.dialog.get_abort(message: str = 'Major problem - or at least we think there is one...', title: str = 'Major problem encountered!')

Displays a message about a problem. If the user clicks on “abort”, sys.exit() is called and the program ends. If the user clicks on “ignore”, the program resumes its execution.

Parameters:
  • title – the window title
  • message – the message to display
>>> from easygraphics.dialog import *
>>> get_abort()
../_images/get_abort.png
easygraphics.dialog.get_choice(message: str = 'Select one item', title: str = 'Title', choices: List[str] = None) → Optional[str]

Simple dialog to ask a user to select an item within a drop-down list

Parameters:
  • message – Message displayed to the user, inviting a response
  • title – Window title
  • choices – iterable (list or tuple) containing the names of the items that can be selected.
Returns:

a string, or None if “cancel” is clicked or window is closed.

>>> from easygraphics.dialog import *
>>> choices = ["CPython", "Pypy", "Jython", "IronPython"]
>>> reply = get_choice("What is the best Python implementation", choices=choices)
../_images/get_choice.png
easygraphics.dialog.get_color_hex(color='white') → Optional[str]

Using a color dialog, returns a color in hexadecimal notation i.e. a string ‘#RRGGBB’ or “None” if color dialog is dismissed.

>>> from easygraphics.dialog import *
>>> color = get_color_hex()
../_images/select_color.png
easygraphics.dialog.get_color_rgb(color='white') -> (<class 'int'>, <class 'int'>, <class 'int'>)

Using a color dialog, returns a color in rgb notation i.e. a tuple (r, g, b) or “None” if color dialog is dismissed.

>>> from easygraphics.dialog import *
>>> color = get_color_rgb()
../_images/select_color_fr.png
easygraphics.dialog.get_color(color='white') → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5350ac5128>

Display a color picker and return the selected color

>>> from easygraphics.dialog import *
>>> color = get_color()
../_images/select_color_fr.png
Returns:the color selected
easygraphics.dialog.get_continue_or_cancel(question: str = 'Processed will be cancelled!', title: str = 'Title', continue_button_text: str = 'Continue', cancel_button_text: str = 'Cancel') → bool

Continue or cancel question, shown as a warning (i.e. more urgent than simple message)

Parameters:
  • question – Question (string) asked
  • title – Window title (string)
  • continue_button_text – text to display on button
  • cancel_button_text – text to display on button
Returns:

True for “Continue”, False for “Cancel”

>>> from easygraphics.dialog import *
>>> choice = get_continue_or_cancel()
../_images/get_continue_or_cancel.png
easygraphics.dialog.get_date(title: str = 'Select Date') → datetime.date

Calendar widget

Parameters:title – window title
Returns:the selected date as a datetime.date instance
>>> from easygraphics.dialog import *
>>> date = get_date()
../_images/get_date.png
easygraphics.dialog.get_directory_name(title: str = 'Get directory') → str

Gets the name (full path) of an existing directory

Parameters:title – Window title
Returns:the name of a directory or an empty string if cancelled.
>>> from easygraphics.dialog import *
>>> get_directory_name()
../_images/get_directory_name.png

By default, this dialog initially displays the content of the current working directory.

easygraphics.dialog.get_file_names(title: str = 'Get existing file names', filter: str = 'All Files (*.*)') → str

Gets the names (full path) of existing files

Parameters:
  • title – Window title
  • filter – file filter
Returns:

the list of names (paths) of files selected. (It can be an empty list.)

>>> from easygraphics.dialog import *
>>> get_file_names()
../_images/get_file_names.png

By default, this dialog initially displays the content of the current working directory.

easygraphics.dialog.get_float(message: str = 'Choose a number', title: str = 'Title', default_value: float = 0.0, min_: float = -10000, max_: float = 10000, decimals: int = 3) → Optional[float]

Simple dialog to ask a user to select a floating point number within a certain range and a maximum precision.

Parameters:
  • message – Message displayed to the user, inviting a response
  • title – Window title
  • default_value – Default value for value appearing in the text box; set to the closest of min_ or max_ if outside of allowed range.
  • min – Minimum value allowed
  • max – Maximum value allowed
  • decimals – Indicate the maximum decimal precision allowed
Returns:

a floating-point number, or None if “cancel” is clicked or window is closed.

>>> from easygraphics.dialog import *
>>> number = get_float()
../_images/get_float.png

Note: depending on the locale of the operating system where this is used, instead of a period being used for indicating the decimals, a comma may appear instead; this is the case for the French version of Windows for example. Therefore, entry of floating point values in this situation will require the use of a comma instead of a period. However, the internal representation will still be the same, and the number passed to Python will be using the familar notation.

easygraphics.dialog.get_int(message: str = 'Choose a number', title: str = 'Title', default_value: int = 1, min_: int = 0, max_: int = 100, step: int = 1) → Optional[int]

Simple dialog to ask a user to select an integer within a certain range.

Note: get_int() and get_integer() are identical.

Parameters:
  • message – Message displayed to the user, inviting a response
  • title – Window title
  • default_value – Default value for integer appearing in the text box; set to the closest of min_ or max_ if outside of allowed range.
  • min – Minimum integer value allowed
  • max – Maximum integer value allowed
  • step – Indicate the change in integer value when clicking on arrows on the right hand side
Returns:

an integer, or None if “cancel” is clicked or window is closed.

>>> from easygraphics.dialog import *
>>> number = get_int()
../_images/get_int.png

If default_value is larger than max_, it is set to max_; if it is smaller than min_, it is set to min_.

>>> number = get_integer("Enter a number", default_value=125)
../_images/get_int2.png
easygraphics.dialog.get_integer(message: str = 'Choose a number', title: str = 'Title', default_value: int = 1, min_: int = 0, max_: int = 100, step: int = 1) → Optional[int]

Simple dialog to ask a user to select an integer within a certain range.

Note: get_int() and get_integer() are identical.

Parameters:
  • message – Message displayed to the user, inviting a response
  • title – Window title
  • default_value – Default value for integer appearing in the text box; set to the closest of min_ or max_ if outside of allowed range.
  • min – Minimum integer value allowed
  • max – Maximum integer value allowed
  • step – Indicate the change in integer value when clicking on arrows on the right hand side
Returns:

an integer, or None if “cancel” is clicked or window is closed.

>>> from easygraphics.dialog import *
>>> number = get_int()
../_images/get_int.png

If default_value is larger than max_, it is set to max_; if it is smaller than min_, it is set to min_.

>>> number = get_integer("Enter a number", default_value=125)
../_images/get_int2.png
easygraphics.dialog.get_list_of_choices(title: str = 'Title', choices: List[str] = None) → easygraphics.dialog._indexed_order_list.IndexedOrderedDict

Show a list of possible choices to be selected.

Parameters:
  • title – Window title
  • choices – iterable (list, tuple, …) containing the choices as strings
Returns:

a list of selected items, otherwise an empty list.

>>> from easygraphics.dialog import *
>>> choices = get_list_of_choices()
../_images/get_list_of_choices.png
easygraphics.dialog.get_many_strings(title: str = 'Title', labels: List[str] = None, masks: List[bool] = None) → easygraphics.dialog._indexed_order_list.IndexedOrderedDict

Multiple strings input

Parameters:
  • title – Window title
  • labels – an iterable containing the labels for to use for the entries
  • masks – optional parameter.
Returns:

An ordered dict containing the labels as keys, and the input from the user (empty string by default) as value

The parameter masks if set must be an iterable of the same length as choices and contain either True or False as entries indicating if the entry of the text is masked or not. For example, one could ask for a username and password using get_many_strings as follows [note that get_username_password exists and automatically takes care of specifying the masks and is a better choice for this use case.]

>>> from easygraphics.dialog import *
>>> labels = ["User name", 'Password']
>>> masks = [False, True]
>>> reply = get_many_strings(labels=labels, masks=masks)
>>> reply
OrderedDict([('User name', 'aroberge'), ('Password', 'not a good password')])
../_images/get_many_strings.png
easygraphics.dialog.get_new_password(title: str = 'Title', labels: List[str] = None) → easygraphics.dialog._indexed_order_list.IndexedOrderedDict

Change password input box.

Parameters:
  • title – Window title
  • labels – an iterable containing the labels for “Old password” and “New password” and “Confirm new password”. All three labels must be different strings as they are used as keys in a dict - however, they could differ only by a space.
Returns:

An ordered dict containing the fields item as keys, and the input from the user as values.

Note: this function is a special case of get_many_strings where the required masks are provided automatically..

>>> from easygraphics.dialog import *
>>> reply = get_new_password()
../_images/get_new_password.png
easygraphics.dialog.get_open_file_name(title: str = 'Get file name for open', filter: str = 'All Files (*.*)') → str

Get a file name for open

Parameters:
  • title – title of the dialog
  • filter – file filter
Returns:

the file name

easygraphics.dialog.get_password(message: str = 'Enter your password', title: str = 'Title') → Optional[str]

Simple password input box. Used to query the user and get a string back.

Parameters:
  • message – Message displayed to the user, inviting a response
  • title – Window title
Returns:

a string, or None if “cancel” is clicked or window is closed.

>>> from easygraphics.dialog import *
>>> password = get_password()
../_images/get_password.png
easygraphics.dialog.get_save_file_name(title: str = 'File name to save', filter: str = 'All Files (*.*)') → str

Gets the name (full path) of of a file to be saved.

Parameters:
  • title – Window title
  • title – Window title
Returns:

the name (path) of file selected

The user is warned if the file already exists and can choose to cancel. However, this dialog actually does NOT save any file: it only return a string containing the full path of the chosen file.

>>> from easygraphics.dialog import *
>>> get_save_file_name()
../_images/get_save_file_name.png

By default, this dialog initially displays the content of the current working directory.

easygraphics.dialog.get_string(message: str = 'Enter your response', title: str = 'Title', default_response: str = '') → Optional[str]

Simple text input box. Used to query the user and get a string back.

Parameters:
  • message – Message displayed to the user, inviting a response
  • title – Window title
  • default_response – default response appearing in the text box
Returns:

a string, or None if “cancel” is clicked or window is closed.

>>> from easygraphics.dialog import *
>>> reply = get_string()
../_images/get_string.png
>>> reply = get_string("new message", default_response="ready")
../_images/get_string2.png
easygraphics.dialog.get_username_password(title: str = 'Title', labels: List[str] = None) → easygraphics.dialog._indexed_order_list.IndexedOrderedDict

User name and password input box.

Parameters:
  • title – Window title
  • labels – an iterable containing the labels for “user name” and “password”; if the value not specified, the default values will be used.
Returns:

An ordered dict containing the fields item as keys, and the input from the user (empty string by default) as value

Note: this function is a special case of get_many_strings where the required masks are provided automatically..

>>> from easygraphics.dialog import *
>>> reply = get_username_password()
>>> reply
OrderedDict([('User name', 'aroberge'), ('Password', 'not a good password')])
../_images/get_username_password.png
easygraphics.dialog.get_yes_or_no(question: str = 'Answer this question', title: str = 'Title') → Optional[bool]

Simple yes or no question.

Parameters:
  • question – Question (string) asked
  • title – Window title (string)
Returns:

True for “Yes”, False for “No”, and None for “Cancel”.

>>> from easygraphics.dialog import *
>>> choice = get_yes_or_no()
../_images/yes_no_question.png
easygraphics.dialog.show_image_dialog(image: <sphinx.ext.autodoc.importer._MockObject object at 0x7f5350ac5128>, title: str = 'Title')

Display the image in a dialog.

Parameters:
  • image – the image to be displayed
  • title – Window title
easygraphics.dialog.show_table(datas: Sequence[T_co], fields: Sequence[str] = None, field_names: Sequence[str] = None, title: str = 'Title', width: int = 720, height: int = 450, enable_sorting=False)

Displays list of objects in a table

>>> from easygraphics.dialog import *
>>> class Person:
>>>     def __init__(self,name,age,sex):
>>>         self.name=name
>>>         self.age = age
>>>         self.sex = sex
>>> objs = [Person("Jack", 22, "M"), Person("Micheal", 40, "F"), Person("David", 24, "M")]
>>> show_objects(title="peoples",datas=objs,fields=["name","age","sex"],field_names=["NAME","AGE","SEX"])
../_images/show_objects.png
Parameters:
  • datas – the object list to show
  • fields – fields to show of the object
  • field_names – the field names displayed on the table header
  • title – title of the dialog window
  • width – width of the dialog window
  • height – height of the dialog window
  • enable_sorting – if data can be sorted by clicking the column name
easygraphics.dialog.show_lists_table(*args, column_names: List[str] = None, title: str = 'Title', width: int = 720, height: int = 450)

Displays list of datas in a table

>>> from easygraphics.dialog import *
>>> x=[1,2,3,4]
>>> y=["hah","jack","marry"]
>>> show_lists_table(x,y,column_names=['x','y'])
.. image:: ../../docs/images/dialogs/show_lists_table.png
Parameters:
  • args – the lists to show
  • column_names – the column names displayed on the table header
  • title – title of the dialog window
  • width – width of the dialog window
  • height – height of the dialog window
easygraphics.dialog.show_html(title: str = 'Title', text: str = '', width: int = 720, height: int = 450)

Displays some html text in a window.

Parameters:
  • title – the window title
  • text – a string to display in the window.
  • width – width of the dialog window
  • height – height of the dialog window
>>> from easygraphics.dialog import *
>>> show_html()
apis/../../docs/images/dialogs/show_html.png
class easygraphics.dialog.FileFilter
AllFiles = 'All Files (*.*)'
CSVFiles = 'CSV Files (*.csv)'
ImageFiles = 'Image Files (*.png *.gif *.jpg *.webp *.bmp)'
PythonFiles = 'Python Files (*.py)'
TxtFiles = 'Text Files (*.txt)'