Python Forum
[Tkinter] How to update widgets?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to update widgets?
#2
I already gave you an example that does exactly what you are asking and the example was based on your code.

https://python-forum.io/Thread-Tkinter-H...#pid134606

This code in particular:
def search(event):
    name = search_box.get()
    unit = units.get(name)
    if unit:
        result_text['text'] = f'Physical quantity :  {name}\nUnit :  {unit[0]}\nSymbol :  {unit[1]}'
    else:
        result_text['text'] = f'Unit "{name}" not found'
    search_box.delete(0, END)
In particular lines 5 or 7.

In addition to this method you could use "result_text.configure(text='whatever text goes in label')

You could also create a tkinter StringVar() and assign this as the textvariable when creating the label.
result_text = StringVar()
Label(results, textvariable = result_text, width= 40, height=3).pack()
..
def search(event):
    name = search_box.get()
    unit = units.get(name)
    if unit:
        result_text.set(f'Physical quantity :  {name}\nUnit :  {unit[0]}\nSymbol :  {unit[1]}')
    else:
        result_text.set(f'Unit "{name}" not found')
    search_box.delete(0, END)
Oshadha likes this post
Reply


Messages In This Thread
How to update widgets? - by Oshadha - Jan-17-2021, 10:13 AM
RE: How to update widgets? - by deanhystad - Jan-18-2021, 04:37 AM

Forum Jump:

User Panel Messages

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