0

I have got a problem with Tkinter. I made a GUI with two lists. On my Mac OS X everything works fine but on Windows my program is working but Tkinter GUI doesn't respond. I read about this and my problem probably is in time.sleep(10) what do I need to use to make a function delay? In my opinion Tkinter doesn't like time.sleep.

def showCars3():
while True:
    global hotList
    print("")   
    hotList.delete(0, END)
    for car in hotCars:
        hotList.insert(END, car.title)
    hotList.update_idletasks()
    time.sleep(10)


t5 = Thread(target = showCars3) 
SF12 Study
  • 375
  • 4
  • 18
Piotr
  • 175
  • 1
  • 2
  • 11
  • 1
    To my knowledge, Tkinter isn't thread safe. If you make changes to the GUI, make them from the thread that's running the Tkinter mainloop. – Aran-Fey Feb 25 '17 at 15:01
  • Why do you need the gui to sleep? Isn't the real problem you're trying to solve is how to insert values every 10 seconds? You don't need to sleep to do that. – Bryan Oakley Jun 28 '19 at 20:35
  • Use python 3. Also, in python functions and variables are named using `lowercase_with_underscores` not camelCase. – Boris Verkhovskiy Jul 22 '19 at 06:07
  • 1
    And see this question https://stackoverflow.com/questions/10393886/tkinter-and-time-sleep – Boris Verkhovskiy Jul 22 '19 at 06:08

2 Answers2

-1

Looks like you have not defined the Tkinter window?

And your indentation is messed:

Yours:

def showCars3():
while True:
    global hotList
    print("")   
    hotList.delete(0, END)
    for car in hotCars:
        hotList.insert(END, car.title)
    hotList.update_idletasks()
    time.sleep(10)

Needed Indentations:

def showCars3():
    while True:
        global hotList
        print("")   
        hotList.delete(0, END)
        for car in hotCars:
            hotList.insert(END, car.title)
        hotList.update_idletasks()
        time.sleep(10)

And no, Tkinter is fine with time.sleep.

If those do not solve your problem, you then need to show me your whole code.

odedbd
  • 2,285
  • 3
  • 25
  • 33
SF12 Study
  • 375
  • 4
  • 18
  • You need to clarify your answer a bit. Tkinter is definitely _not_ fine with sleep. If you put the sleep in another thread it's ok, but if it's in the same thread as the GUI it will cause the UI to freeze. – Bryan Oakley Jun 28 '19 at 20:35
  • Mine works really well with time.sleep. – SF12 Study Jun 29 '19 at 07:13
-2

Have you got:

import time

somewhere above your code?

a_ko
  • 149
  • 1
  • 2
  • 10