在 tkinter 中绘制图形

问题描述

我试图通过阅读一些列表在 tkinter 窗口中绘制图形。这些列表每次都会更新,我希望图表随列表值而变化。

我正在使用“Canvas_create.line()”绘制图形,并在 tkinter 窗口中为每个值提供坐标。

我在“while True”循环中读取了这些值,但是当我放入“root.mainloop()”语句时,过程停止。

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()

我不知道我该怎么做。谢谢各位。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)