0

I'm trying to draw a graph in a tkinter window by reading some lists. These list are updating every time and I want the graphs change with the lists values.

I'm drawing the graphs with 'Canvas_create.line()' and giving coordinates in the tkinter window for each value.

I read these values inside I 'while True' loop, but when I put the 'root.mainloop()' sentence the process stops.

def drawAnalogicValues(variable,windowDraw,supValue,infValue):
    
    global Change, StepX
    
    Change = True 
    while True:
        if Change == True: # If 'Change' = True, start drawing the variable
            indexVariable = int(variable[1:])
            valuesVariable = MatrixA_Values[indexVariable] # Se actual variable values
            Change = False # Change the global variable 'Change' to False.
            
            # Top and down coordx of window
            coordYSup = 48
            coordYInf = 452
            rangePrint = coordYInf - coordYSup
            # CorrdX to start the graph
            coordXStart = 193
            StepX = 0
            for i in range(len(valuesVariable)-1):
                actual = int(valuesVariable[i])         
                if valuesVariable[i+1] != None:
                    next = int(valuesVariable[i+1])
                else:
                    # If none in list valuesVariable, the draw stops 
                    break
                # CoordX where is the graph for each step
                coordX = coordXStart + StepX    
                # CoordY 'actual' and 'next' value
                relativeActual = (valueSup-actual)/(valorSup - valorInf)   # Percentage of the value, respect 'valueSup'
                relativeNext = (valueSup-actual)/(valueSup - valueInf)
                
                coordYActual = coordYSup + rangePrint*relativeActual
                coordYNext = coordYSup + rangePrint*relativeNext
                # Line for 'actual' to 'next' point
                windowDraw.create_line(coordX,coordYActual,coordX+2,coordYNext,fill = 'red')
                
                StepX = StepX + 2
                
        windowDraw.mainloop()

I have no idea how can I do it. Thank you guys.

  • You shouldn't use `while True` loops when working with `tkinter`. Use `.after` scripts instead. Also unless you provide a minimal version of your code, there is no way we can debug your program. – TheLizzard Jun 13 '21 at 10:40
  • Thank you, I've post part of the code – betoelpuerco Jun 13 '21 at 11:33
  • 4
    Does this answer your question? [Placing plot on Tkinter main window in Python](https://stackoverflow.com/questions/31440167/placing-plot-on-tkinter-main-window-in-python) – itprorh66 Jun 13 '21 at 15:02

0 Answers0