Egor. L
Egor. L

Reputation: 169

Python: Live update of lists and dictionaries?

Python 3.6

Hello all, I can't seem to figure out how to get my GUI interface to live update a label. This label contains information from a list and this list is manipulated via buttons. However the number does not update! I've have tried using after() but after many failed attempts I don't understand how to get it to work.

Would I need to put it into a function that would then update my GUI? Or how else could I achieve this? I am still learning to program and very new to it. Any other tips are greatly appreciated! Thank you!

My label:

stock5 = Label(Stockframe, font=('Agency FB',20), text=(stock['Intel i7-
7770T QUAN'][0]))
stock5.grid(row=0, column=5)

My list:

{'Intel i7-7770T QUAN' : [3] }

I have tried this but to no success:

def updater():

     after(1000, updater)

     updater()

I am most probably misunderstanding how to use after()! Thank you!

Upvotes: 0

Views: 67

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386020

Your updater function needs to actually update the label.

Assuming that stock5 and stock are global variables, and assuming that you are somehow updating stock on a regular basis, something like this would work:

def updater():
    new_value = stock['Intel i7-7770T QUAN'][0]
    stock5.configure(text=new_value)
    after(1000, updater)

Upvotes: 2

Related Questions