Python 从输入实时创建图像,python3

Python real-time create image from input, python3

大约每秒钟(有时每秒两次)我从 COM 端口收到一个数据,例如:[1 2 3 1]。

此列表表示图像的一部分 - 第一条垂直线。

我想实时绘制整个图像,就像扫描仪一样。

例如:

First data coming:
x
x
x 
x

Second
x x
x x
x x
x x
..
After N - data tacking:
x x x ... x
x x x ... x
x x x ... x
x x x ... x

我该怎么做?

我想,我需要积累数组,比如:

Array=list()
new_data=..
Array.append(new_data)
*Create_image*

[已编辑]试试这个:

from tkinter import *
root = Tk()
cans=Canvas(root,height=500,width=600)
cans.pack()
delay = 1  # milliseconds
array_list=[] # this will be list of arrays

def get_new_data():
    new_data=[]
    new_data = #whatever write code here how you get next new list from somewhere
    array_list.append(raw_data)    
    return array_list

def get_lits(x):
    get_new_data()
    return array_list[x-2]

def get_color(y, x):
    max_num = 15
    raw_array=get_data(x)
    c = raw_array[y] * 255 / max_num
    colorname = '#%02x%02x%02x' % (c, c, c)
    return colorname

def draw_line(i=2, j=0):
    if i <= 600:
        if j<=500:
            cans.create_line(i,j,i+1,j, fill=get_color(j, i))
            root.after(delay, draw_line, i+0, j+1)
        elif j>150:
            j=0
            root.after(delay, draw_line, i+1)
draw_line()       
root.mainloop()

只需编写代码如何在 get_new_data() 中获取新数组,同时将 max_num =12 更改为数组的最大值。