Python-Yad
The Yad-Dialog
Yad is Linux program that allows the user to create simple GUI Dialogs on the screen using shell scripts. Its a fork of Zenity with a lot of extended features. For example, a calendar dialog can be bought up by opening the terminal and typing in the following command (assuming yad is installed in the system) :
yad --calendar --day 14 --month 10 --year 2015
And you will get something like this :
You should check its man-pages
for more options :
man yad
The Python Interface
I created a python interface for this program. It depends on the yad
, and the pexpect
module. You can pretty much achieve the same results as the original. So, to get the calendar dialog as in the previous example, what you got to do is :
- Create a python script or enter the python shell in the terminal.
- Import the python-yad module and call the
YAD()
class. - And finally call the calendar as
yad.Calendar()
Here is the sample python code :
#!/usr/bin/env python
from yad import YAD
yad = YAD()
dates = yad.Calendar(day="14", month="10", year="2015")
It will return either the date that were selected in the dialog or none
. I made a clear documentation and its very easy to understand. You got to check out the YAD
class for the parameters and examples.
The working of the interface is very simple. It generates a string with the appropriate parameters when the function is called. This string is then passed to a subprocess that is created with the pexpect
module and then executed.
So, if you are doing a small project in python on linux and you need a simple GUI interaction, then yad is the best bet, in my opinion. The installation and usage instructions are given in the links below.
Resources
- Python-yad : https://pypi.python.org/pypi/yad/
- Yad-Dialog : http://sourceforge.net/projects/yad-dialog/
- Zenity : https://help.gnome.org/users/zenity/stable/
I feedback.
Let me know what you think of this article on twitter @dvenkatsagar or leave a comment below!