Python Tkinter - Get Selected Combobox Value

How To Get Selected Item Value From A Tkinter Combobox Using Python

Python Tkinter - Get Combobox Value

In This Python Tkinter Tutorial we will See How To Get The Value Of The Selected Item From a Tkinter combobox On ComboboxSelected Event Using Python.


Source Code:


import tkinter as tk
from tkinter import *
from tkinter import ttk


root = Tk()

root.title("Get Combobox Value")

frame = tk.Frame(root, padx=40,pady=40, bg='grey')


options = ["Python","C#","Java","Php","C++","VB.Net","JavaScript"]
selected = StringVar(frame)
selected.set(options[0])

combobox = ttk.Combobox(frame, textvariable=selected, values=options,
font=('verdana',20))

label = tk.Label(frame, text="Username:", bg="grey",fg="#fff", font=("Verdana",20))
input_entry = tk.Entry(frame, width=20, font=("Verdana",20))

def getSelectedItem(eventObject):
print(combobox.get())
label['text'] = combobox.get()
input_entry.delete(0,END)
input_entry.insert(0,combobox.get())


combobox.bind("<<ComboboxSelected>>", getSelectedItem)

combobox.grid(row=0, column=0)
label.grid(row=1, column=0)
input_entry.grid(row=2, column=0)
frame.pack()

root.mainloop()

OUTPUT:

Get Combobox Value In Python Tkinter

Get Combobox Value Using Python Tkinter

Get Combobox Selected Value Using Python Tkinter

Get Combobox Selected Option Value Using Python Tkinter






Share this

Related Posts

Previous
Next Post »