Python Forum
.get() not retrieving value?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.get() not retrieving value?
#2
Here is an example using a callback function

import tkinter as tk
from tkinter import ttk

# Function to print value. Using combo.get() to get the value
def callback(event):
    label['text'] = f'Selected: {combo.get()}'

root = tk.Tk()
root.geometry('400x200+300+300')

# Label to display text
label = tk.Label(root, anchor='w')
label.pack(fill='x',padx=10)

# Some values to populate the combobox
values = [(f'Value {i}') for i in range(11)]

# Define the combobox
combo = ttk.Combobox(root, state='readonly')
combo['values'] = values
combo.current(0)
combo.pack(pady=5)

# Bind the combobox and set the function callback
combo.bind('<<ComboboxSelected>>', callback)

# Print starting value for label
label['text'] = callback(event=None)

root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
.get() not retrieving value? - by Sedos101 - Aug-25-2023, 06:02 AM
RE: .get() not retrieving value? - by menator01 - Aug-25-2023, 08:25 AM
RE: .get() not retrieving value? - by deanhystad - Aug-25-2023, 11:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  KeyError while retrieving ESPN data john317ab 2 868 Nov-29-2023, 09:07 PM
Last Post: john317ab
  [Solved] Retrieving a pdf from sqlite3 BigMan 4 2,433 Mar-12-2022, 01:56 PM
Last Post: deanhystad
  Retrieving a column from a data set using a function Bayle 6 2,426 Oct-06-2021, 08:52 PM
Last Post: Bayle
  Retrieving Cookies whois1230 2 2,232 Nov-21-2020, 12:01 PM
Last Post: snippsat
  Problem: Retrieving Form data PythonDev 3 3,147 Oct-16-2020, 02:09 AM
Last Post: PythonDev
  Retrieving dictionary keys within with another dictionay bazcurtis 8 2,913 Oct-29-2019, 10:06 PM
Last Post: bazcurtis
  Retrieving items from JSON bazcurtis 12 5,163 Oct-27-2019, 05:18 PM
Last Post: bazcurtis
  Trouble retrieving dictionary from mysql.connector cursor swechsler 2 3,117 Sep-17-2019, 05:21 PM
Last Post: swechsler
  retrieving pvalue from statsmodels results Staph 4 3,088 Jul-18-2019, 03:27 PM
Last Post: Gribouillis
  PRAW and PyQt: Immense slowdown when retrieving Reddit posts and adding them to GUI codebro 2 3,264 Dec-30-2018, 01:19 AM
Last Post: codebro

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020