Welcome folks today in this blog post we will building a combobox or select list
in tkinter using python. All the full source code of the application is given below.
Get Started
In order to get started you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
from tkinter import * from tkinter import ttk from tkinter import messagebox root = Tk() root.geometry("400x400") #^ Length and width window :D cmb = ttk.Combobox(root, width="10", values=("prova","ciao","come","stai")) #^to create checkbox #^cmb = Combobox #now we create simple function to check what user select value from checkbox def checkcmbo(): if cmb.get() == "prova": messagebox.showinfo("What user choose", "you choose prova") #^if user select prova show this message elif cmb.get() == "ciao": messagebox.showinfo("What user choose", "you choose ciao") #^if user select ciao show this message elif cmb.get() == "come": messagebox.showinfo("What user choose", "you choose come") elif cmb.get() == "stai": messagebox.showinfo("What user choose", "you choose stai") elif cmb.get() == "": messagebox.showinfo("nothing to show!", "you have to be choose something") cmb.place(relx="0.1",rely="0.1") btn = ttk.Button(root, text="Get Value",command=checkcmbo) btn.place(relx="0.5",rely="0.1") root.mainloop() |
Now if you execute the python
script by typing the below command
python app.py