-1

I am creating a program in which i want to update values continuously after click start.

Until user clicks on Stop button i want values to keep updating

I use for loop for testing like

    for i in range(1000):
        window[-TEXT-].update(function())

Basically after the loop complete running it update the value directly last i value

I also use time.sleep(0.1) to keep track of it but didn't work

Robert
  • 7,394
  • 40
  • 45
  • 64
  • 1
    Like all GUI frameworks, PySimpleGui is event driven. When you make an update, nothing gets drawn -- that just sends a message. The message will be dispatched and handled when you get back to the main loop. As long as you are looping, the main loop cannot run, and your UI cannot update. You need to use timers and timer events for this. Also note that you can't literally "update continuously" -- your monitor only refreshes about 60 times a second. – Tim Roberts Dec 30 '21 at 04:02

1 Answers1

1

Call window[-TEXT-].update(function()) won't update the GUI, how to update GUI ?

  • Loop to next window.read(), or
  • call window.Refresh() after it

You can use option timeout of window.read to count it if it is periodic.

count = 1000

while True:

    event, values = window.read(timeout=20)     # 20ms

    if event in (sg.WINDOW_CLOSED, 'Exit'):
        break

    elif event == sg.TIMEOUT_EVENT and count:
        window[-TEXT-].update(function())
        count -= 1

window.close()
Jason Yang
  • 11,284
  • 2
  • 9
  • 23