0

I am writing a GUI using tkinter that has a graph inside the main and only window. I have to update the value of the graph every 2 seconds (as I received data every 2 seconds from a serial port). I have been able to do this by using tkinter canvas.draw(). My problem is that every time the canvas is drawn (these 2 seconds), the GUI freezes for some time, and if for example I am writing a value in an entry or selecting a value of a list in the GUI in that moment, the GUI stops working temporarily and I have to click again with the mouse in the entry, so it is not convenient. I guess that the GUI is redrawing completely all the window. However I only want to redraw the graph. By the way, I am using matplolib for the graph.

So my questions are:

  1. Is it possible to avoid this problem?
  2. If it is not possible, what are the alternatives? maybe creating another tkinter window only for the graph?.
6
  • 1
    solution 3. reduce the data you are drawing, 2 seconds means you are drawing too much information, think of another way to represent the data with less drawing elements. Commented Jun 30, 2024 at 17:03
  • 1
    solution 4. re-implement Tkinter Matplotlib Canvas to do plotting in another thread then just blit the result on your screen when done Commented Jun 30, 2024 at 17:04
  • @AhmedAEK I received the data every 2 seconds from a serial port. I think I need to do the dedicated thread thing. Any easy example on how to do it?. Commented Jun 30, 2024 at 17:05
  • 1
    the re-implementing part means you have to re-implement all user interactions (clicking, scrolling, dragging), and you need to transfer data between threads solely as a PIL.Image, don't try doing any calls to the canvas from the other thread, those things are not thread-safe. Commented Jun 30, 2024 at 17:07
  • That seems a lot of work but I will try my best. Many thanks! Commented Jun 30, 2024 at 17:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.