0

After the tkinter gui is open i want to change the name every x seconds referencing from an api in my code

ws.mainloop() # ----------------------------------------- starttime = time.time() while True: Value1 = data["session"]["gameType"] Value2 = data["session"]["mode"] Value3 = ' / ' Value = Value1 + Value3 + Value2 ws.title(Value.lower()) time.sleep(60.0 - ((time.time() - starttime) % 60.0)) 

After the gui opens anything below it does not get ran until the program is closed.

1
  • 1
    mainloop will not exit until the application is closed, and should be the last thing in your main. You must use ws.after to request a callback after a certain amount of time. You must think "event driven", and not linear. Commented Mar 22, 2022 at 1:49

1 Answer 1

2

You can use .after() to run a function after given delay:

after(ms, func=None, *args) Call function once after given time. 'ms' specifies the time in milliseconds. 'func' gives the function which shall be called. Additional parameters are given as parameters to the function call. Return identifier to cancel scheduling with after_cancel. 

Below is an example:

def update_title(starttime=time.time()): Value1 = data["session"]["gameType"] Value2 = data["session"]["mode"] Value3 = ' / ' Value = Value1 + Value3 + Value2 ws.title(Value.lower()) delay = 60.0 - ((time.time() - starttime) % 60.0) # schedule next function execution ws.after(int(delay*1000), update_title, starttime) update_title() # start the periodic update task ws.mainloop() 
Sign up to request clarification or add additional context in comments.

6 Comments

Did you intend for ws.after(...) to call update_title instead of update?
@BryanOakley Yes. It is a typo and thanks for your good catch.
Hey, sorry for late reply. This didnt work for me, it does set the title to the proper reference from the api, but when it loops back and resets it its only setting the title again to what the api already knows, so is it possible to also loop fetching the api so it can update to the new reference the api is giving?
My answer is based on the provided code. There is no code related to api that you said in your comment.
paste-bin.xyz/45165 view the full thing there, sorry about that
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.