Get value from combobox and put it somewhere. . .
FEATURES:
| FRONTEND | • Comboboxes • Labels • Text widgets (textboxes) |
| BACKEND | .get, .insert ref stringVar intVar |

| TRY IT: | 1) Click the combobox dropdown 2) Select an item in the combobox 3) Click button to put the selected item in the textbox 4) Click button to put the selected item in your console |
ENGINE:
CONTENT:
TRY THIS:
ref, .get, .insert, stringVar, intVar,
Labels, Combo boxes, Text widgets (textboxes) Click the combobox dropdown, select an item in the combobox, click button to put the selected item in the textbox, click button to put the selected item in your code editor (IDE) console.
Click the combobox dropdown, select an item in the combobox, click button to put the selected item in the textbox, click button to put the selected item in your code editor (IDE) console.
| BACKEND | COMPONENTS |
|---|---|
| 1) | ref |
| 2) | .get |
| 3) | .insert |
| 4) | stringVar |
| 5) | intVar |
FORMATTING TIP: Notice how the frame for Example-1 is not as wide as the frame for Example-2. The reason is because the text in the Example-1 ‘description label’ is wrapped using the ‘wraplength’ attribute (see line ___). Whereas the wrap in the Example-2 ‘description label’ is forced using ‘n’, which is the code for ‘return’. The frame flexes because ____ .
TRY THIS: In line ___, change the wraplength amount and see how the Example-1 frame width changes.
TRY THIS: In line ___, move the move or delete the ‘n’ to see how the Example-2 frame width changes.
# >https://gist.github.com/ian-weisser/10013110
# >https://stackoverflow.com/questions/36831317/
# >problems-with-tkinter-autocomplete-entry-widget
# >https://stackoverflow.com/questions/66300831/
# >display-which-widget-has-focus
import sys
import os
import tkinter
import tkinter as tk
from ttkwidgets.autocomplete import AutocompleteEntry
from tkinter import *
__version__ = "1.0"
# >||||||||| CREATE WINDOW |||||||||||||||||||||||||||||||
if _hits != self._hits:
self._hit_index = 0
self._hits = _hits
# >only allow cycling if we are in a known hit list
if _hits == self._hits and self._hits:
self._hit_index = (self._hit_index + delta) % len(self._hits)
# >now finally perform the auto completion
if self._hits:
self.delete(0, tkinter.END)
self.insert(0, self._hits[self._hit_index])
self.select_range(self.position, tkinter.END)
def handle_keyrelease(self, event):
"""event handler for the keyrelease event on this widget"""
checkEntry1(1) # >--------------------
checkEntry2(1) # >--------------------
checkEntry3(1) # >--------------------
checkEntry4(1) # >--------------------
# >Then run
if event.keysym == "BackSpace":
if self.position < self.index(END):
# self.delete(self.position, END)
self.delete(self.index(END))
else:
self.position = self.index(END)
if event.keysym == "Left":
if self.position < self.index(END):
self.position = self.index(1)
if event.keysym == "Right":
self.position = self.index(END)
if event.keysym == "Down":
self.autocomplete(1)
if event.keysym == "Up":
self.autocomplete(-1)
if len(event.keysym) == 1:
self.autocomplete()
# > 1) When RETURN key is pressed
def handleReturn(event):
print("RETURN event widget is",event.widget)
print("FOCUS AFTER PRESSING RETURN is on:",root.focus_get())
root.bind("<Return>", handleReturn)
# > 2) When something is SELECTED in a Listbox
def handleListboxSelect(event):
print("SELECT event widget is", event.widget)
root.bind("<<ListboxSelect>>", handleListboxSelect)
def focus(event):
focused_widget = event.widget.winfo_class() f'{focused_widget} has focus'
print(focused_widget, "HAS FOCUS")
root.bind('<FocusIn>', focus)
def updateLb1(data_lb1):
# Clear listbox
lb1.delete(0, END)
# Add items to listbox
for item in data_lb1:
lb1.insert(END, item)
def updateLb2(data_lb2):
lb2.delete(0, END)
for item in data_lb2:
lb2.insert(END, item)
def updateLb3(data_lb3):
lb3.delete(0, END)
for item in data_lb3:
lb3.insert(END, item)
def updateLb4(data_lb4):
lb4.delete(0, END)
for item in data_lb4:
lb4.insert(END, item)
def checkEntry1(e):
typed = entry1.get()
if typed == "":
data_lb1 = list_Formation
else:
data_lb1 = []
for item in list_Formation:
if item.lower().startswith(typed.lower()):
data_lb1.append(item)
# update listbox only with items that match characters typed
updateLb1(data_lb1)
def checkEntry2(e):
typed = entry2.get()
if typed == "":
data_lb2 = list_Side
else:
data_lb2 = []
for item in list_Side:
if item.lower().startswith(typed.lower()):
data_lb2.append(item)
updateLb2(data_lb2)
def checkEntry3(e):
typed = entry3.get()
if typed == "":
data_lb3 = list_Spread
else:
data_lb3 = []
for item in list_Spread:
if item.lower().startswith(typed.lower()):
data_lb3.append(item)
updateLb3(data_lb3)
def checkEntry4(e):
typed = entry4.get()
if typed == "":
data_lb4 = list_Motion
else:
data_lb4 = []
for item in list_Motion:
if item.lower().startswith(typed.lower()):
data_lb4.append(item)
updateLb4(data_lb4)
Reputable theme developers should give you a quick response with a new theme file. If you’re the theme developer, read this guide on creating child themes, especially the section about making a stylesheet. Look for a new theme: This is most likely the best course of action, considering it’s rare for a quality theme developer to miss one of the most critical parts.
Technical Information
Dates:
Original Posted:
Last Updated:
Versions Tested On:
Python:
3.12, 3.13, 3.14
Tkinter:
3.12, 3.13, 3.14
Pycharm:
3.12, 3.13
