-1

I wrote a small program that displays the train arrival times by my house. It updates every seven seconds. The program runs great on my computer (macOS), but on pi (raspbian) the lines displaying the trains flash and then disappear in a weird pattern. For example, for the first two rotations, all the trains display perfectly. Then on the second rotation, the station name will flash and then disappear. Then on the third rotation, the title and the first five trains will disappear. Then on the fourth rotation the cycle will start again. The program is written in Python with tkinter. I know it’s not a monitor issue like the monitor itself blacking out because the monitor has no problems when the program isn’t running. I will link videos of the program running on my laptop and on the pi below.

The logic of how the lines disappear (paraphrased):

while True:
    line = requests.get(api)
    line.pack()
    window.update()
    line.after(7, line.destroy())
    time.sleep(7)

Then the API is called again and new lines populate.

Please help, I have been stuck on this for months.

Program running on raspbian:

https://vimeo.com/731101731

Program running normally on laptop:

https://vimeo.com/731102051

codingkat
  • 1
  • 1
  • 2
    Assuming you are using [requests](https://requests.readthedocs.io/en/latest/), `requests.get` returns a `Response` instance, *not* a`tkinter` widget. So how this code can actually work is a mystery. Please add your complete code to the question. – Roland Smith Jul 18 '22 at 19:19
  • 1
    Also, you are basically rolling your own `mainloop`, which is generally not a good idea. – Roland Smith Jul 18 '22 at 19:27
  • 1
    `line.after(7, line.destroy())` will _immediately_ call `line.destroy()` and then pass the result (`None`) to `line.after`. – Bryan Oakley Jul 18 '22 at 19:41
  • @RolandSmith The code is paraphrased. There is non-consequential parsing of the response object to get the couple bits of info I am interested in. This JSON parsing is not related to the issue I'm asking about so I omitted it to keep the question simple. – codingkat Jul 18 '22 at 22:51
  • I removed the parentheses after line.destroy() in the call to the after() function after reading the comment from @bryan-oakley and that fixed the issue perfectly!! Thank you – codingkat Jul 18 '22 at 22:51

1 Answers1

0

I changed

line.after(7, line.destroy())

to

line.after(7, line.destroy)

so the destroy() function is not called immediately as described by @bryan-oakley in the comments

codingkat
  • 1
  • 1