每隔大约一秒钟(有时两次)我有一个来自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*
答案 0 :(得分:0)
[已编辑]试试这个:
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
更改为数组的最大值。