Using a Combobox in Tkinter
Here we have delivered a complimentary video to How to create a graphical user interface in Tkinter, demonstrating how a Combobox can be used to select values and then validate the entry chosen.
Using a Combobox in the computer programming world has been in use for some time. It is a useful way to select from a choice and could in many ways in data analytics help as the following examples show:
- Select a date to filter a data set down to values that are in the dataset at that point.
- Using matplotlib to plot data points in charts, you could have dynamic values that change the diagram based on values chosen from the Combobox.
- Utilising data analytics reports that the user accesses, the Combobox could be used to change the data shown dynamically to allow comparisons.
- When looking to fix data quality issues, use the Combobox to select values for a date that needs to be fixed, apply the fixes on screen and then save back to the database.
Developing a Tkinter GUI and the possibilities it brings
In this video, we use ttk, written to help split the behaviour of code from the code implementing its appearance; you can see plenty more on it here ttk information. You will find this a handy piece of functionality so that styling an object will not interfere with how it works.
We also have a function that helps with the validation as follows:
def checkifireland (): x = combolist.get() # asssigns the value inside the combobox to x so it can be processed if x == "Ireland": messagebox.showinfo("Correct answer", "You will love it in Ireland") else: messagebox.showinfo("Incorrect answer", "You should visit Ireland first!")
The effectiveness is especially handy as it helps to ensure that the code returned from the Combobox to the function is correct, as the below video will show.
The next steps
There are many informative Python – working with excel videos which are on our YouTube channel.
We are looking to bring them in and show on a graphical user interface tutorial.
If you subscribe to the channel, you will get to see those videos as they are uploaded.