So far our RSS reader has been completely command-line, which is functional but not as nice as we’d really like to have it. So what we are going to do is integrate the GUI that I created in my two Tkinter GUI tutorials into our RSS application.
If you look at our GUI application you can see that at this point it actually has the basic look that we’ll want, what it doesn’t have is the functionality attached to to GUI. So the first thing that we are going to do is let the user add an RSS site when the press the Add button. We are going to pop up a dialog and let them enter the name of the RSS site and the address of the RSS feed.
In order to do that we are going to have to create a simple dialog. Fortunately Tkinter has a nice simple dialog interface that makes creating simple pop-up dialogs quite easy. It’s not as robust as you might like, but if you really wanted to do something very complicated you could simply create another window in the same way that we created our main window. Since we don’t need anything fancy we”ll use the Simple dialog.
To start we must import the simple dialog into our program, so the following will have to be added to the top of the code:
Now we could create create our dialog class in a totally new python file but since it’s going to be pretty simple I decided to keep all together in our one GUI file. The first step in understanding the simple dialog is to read PythonWare’s introduction to the dialog window it will explain all that you need to know to create a simple dialog.
Basically what you need to do is create a class whose parent is the simple dialog:
Then you have to create a body function, this is the function that the tkSimpleDialog assumes will be used to create the body of the dialog. The definition of the body function is as follows:
def body(self, master):
Pretty simple so far right? There are a few other important functions that you need to know about to create a simple dialog, like when to process the data after the Ok button is pressed:
Continue reading RSS reader – Part Four – Integrating with the GUI