我在刷新框架时遇到一些问题tkinter。我应该关闭窗口来刷新我的框架。我的热传感器值每次都在变化。我看了root.after(),但我没有得到它。
不关闭怎么办?
我的代码在这里:
try:
from tkinter import *
except ModuleNotFoundError:
from tkinter import * # Python 3
f = open('text.txt', 'r')
nodes_list = [[int(item) for item in line.split()] for line in f]
heat_map = nodes_list
heat_min = min(min(row) for row in heat_map)
heat_max = max(max(row) for row in heat_map)
print('hello')
palette = (0, 0, 1), (0, .5, 0), (0, 1, 0), (1, .5, 0), (1, 0, 0)
def pseudocolor(value, minval, maxval, palette):
""" Maps given value to a linearly interpolated palette color. """
max_index = len(palette)-1
# Convert value in range minval...maxval to the range 0..max_index.
v = (float(value-minval) / (maxval-minval)) * max_index
i = int(v); f = v-i # Split into integer and fractional portions.
c0r, c0g, c0b = palette[i]
c1r, c1g, c1b = palette[min(i+1, max_index)]
dr, dg, db = c1r-c0r, c1g-c0g, c1b-c0b
return c0r+(f*dr), c0g+(f*dg), c0b+(f*db) # Linear interpolation.
def colorize(value, minval, maxval, palette):
""" Convert value to heatmap color and convert it to tkinter color. """
color = (int(c*255) for c in pseudocolor(value, minval, maxval, palette))
return '#{:02x}{:02x}{:02x}'.format(*color) # Convert to hex string.
root = Tk()
root.title('Heatmap')
width, height = 500, 500 # Canvas size.
rows, cols = len(heat_map), len(heat_map[0])
rect_width, rect_height = width // rows, height // cols
border = 1 # Pixel width of border around each.
canvas = Canvas(root, width=width, height=height)
canvas.pack()#goruntuyu gosteren kisim
text.txt 是这样的。
22 5 9 15 22 20 20 20
22 33 32 15 22 22 20 20
23 34 33 15 22 22 20 20
25 35 35 15 22 25 20 20
12 15 35 15 10 5 20 20
15 40 33 15 3 5 20 15
16 32 25 15 12 22 50 15
13 32 31 15 5 22 23 13
神不在的星期二
相关分类