Python 3 Tkinter ComboBox Widget Example Script to Display Select List and Get Value of Selected Combobox in GUI Desktop App Full Project For Beginners

Python 3 Tkinter ComboBox Widget Example Script to Display Select List and Get Value of Selected Combobox in GUI Desktop App Full Project For Beginners

 

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

 

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()

 

See also  Python 3 Script to Test Internet Speed in Command Line Using SpeedTest Module Full Project For Beginners

 

Now if you execute the python script by typing the below command

 

python app.py

 

 

 

Leave a Reply