#python #user-interface #tkinter
Вопрос:
m new in Python script with tkinter. I
я ищу, чтобы создать систему мониторинга температуры,и я сталкиваюсь с проблемой» Я хочу, чтобы мое изображение из AMG8833 находилось в середине окна tk, и я не знаю, как в моем приложении для пользовательского интерфейса, что интерполяция изображения amg8833 должна быть включена в центр окна белой области
def heatmap():
t0 = time.time()
sensor = []
while (time.time()-t0)<1: # wait 1sec for sensor to start
try:
# AD0 = GND, addr = 0x68 | AD0 = 5V, addr = 0x69
sensor = amg8833_i2c.AMG8833(addr=0x69) # start AMG8833
except:
sensor = amg8833_i2c.AMG8833(addr=0x68)
finally:
pass
time.sleep(0.1) # wait for sensor to settle
# If no device is found, exit the script
if sensor==[]:
print("No AMG8833 Found - Check Your Wiring")
sys.exit(); # exit the app if AMG88xx is not found
#
#####################################
# Interpolation Properties
#####################################
#
# original resolution
pix_res = (8,8) # pixel resolution
xx,yy = (np.linspace(0,pix_res[0],pix_res[0]),
np.linspace(0,pix_res[1],pix_res[1]))
zz = np.zeros(pix_res) # set array with zeros first
# new resolution
pix_mult = 6 # multiplier for interpolation
interp_res = (int(pix_mult*pix_res[0]),int(pix_mult*pix_res[1]))
grid_x,grid_y = (np.linspace(0,pix_res[0],interp_res[0]),
np.linspace(0,pix_res[1],interp_res[1]))
# interp function
def interp(z_var):
# cubic interpolation on the image
# at a resolution of (pix_mult*8 x pix_mult*8)
f = interpolate.interp2d(xx,yy,z_var,kind='cubic')
return f(grid_x,grid_y)
grid_z = interp(zz) # interpolated image
# creating the Tkinter canvas
# containing the Matplotlib figure
vmin=0
vmax=40
plt.rcParams.update({'font.size':16})
fig_dims = (6,6) # figure size
fig,ax = plt.subplots(figsize=fig_dims) # start figure
fig.canvas.set_window_title('AMG8833 Image Interpolation')
im1 = ax.imshow(grid_z,vmin=vmin,vmax=vmax,cmap=plt.cm.RdBu_r) # plot image, with temperature bounds
#im2 = ax.imshow(grid_z , T_thermistor , cmap=plt.cm.Rdbu_r)
cbar = fig.colorbar(im1,fraction=0.0475,pad=0.03) # colorbar
cbar.set_label('Temperature [C]',labelpad=10) # temp. label
cbar.set_label('Thermistor:',labelpad=8) # therm label
canvas = FigureCanvasTkAgg(fig,
master = window)
canvas.draw()
# placing the canvas on the Tkinter window
fig.canvas.get_tk_widget().grid(row=1,column=2)
# creating the Matplotlib toolbar
toolbar = NavigationToolbar2Tk(canvas,
window)
toolbar.update()
# placing the toolbar on the Tkinter window
canvas.get_tk_widget().grid(row=1,column=2)
#
#####################################
# Plot AMG8833 temperatures in real time
#####################################
#
pix_to_read = 64 # citeste toti 64 pixeli
while True:
status,pixels = sensor.read_temp(pix_to_read) # status pixels read
if status: # if error in pixel, re-enter loop and try again
continue
T_thermistor = sensor.read_thermistor() # citire temperatura thermistor
canvas.restore_region(ax_bgnd) # restore background
new_z = interp(np.reshape(pixels,pix_res)) # imagine interpolata
im1.set_data(new_z) # update la plot cu imaginea interpolata
ax.draw_artist(im1) # deseneaza imaginea din nu
canvas.blit(ax.bbox) # viteza mai mare de rulare
canvas.flush_events() # plot in timp real
#print("Thermistor Temperature: {0:2.2f}".format(T_thermistor ))
window = tk.Tk()
window.title("System Monitoring Temperature")
window.rowconfigure(0, minsize=600, weight=1)
window.columnconfigure(1, minsize=600, weight=1)
txt_edit = tk.Text(window)
fr_buttons = tk.Frame(window, relief=tk.RAISED, bd=2)
btn_open = tk.Button(fr_buttons, text="Open", command=open_file)
btn_save = tk.Button(fr_buttons, text="Save As...", command=save_file)
btn_verificare= tk.Button(fr_buttons, text="Verificare senzor ..", command=verificare_senzor)
btn_pornire= tk.Button(fr_buttons, text="Temperatura termistor..", command=thermistor_temperature)
btn_heatmap=tk.Button(fr_buttons, text="Heatmap..", command=heatmap)
btn_quit = tk.Button(fr_buttons, text="Inchidere .. ",fg='red',command=destroy)
btn_alarma= tk.Button(fr_buttons, text="Alarma ...", bg='red', command= alarm)
btn_open.grid(row=0, column=0, sticky="ew", padx=5, pady=5)
btn_save.grid(row=1, column=0, sticky="ew", padx=5)
btn_verificare.grid(row=6, column=1, sticky="ew", padx=5)
btn_pornire.grid(row=7,column=1, sticky="ew", padx=5)
btn_heatmap.grid(row=8,column=1,sticky="ew", padx=5)
btn_alarma.grid(row=9, column=1, sticky="ew", padx=5, pady=5)
btn_quit.grid(row=10, column=1, sticky="ew", padx=5)
fr_buttons.grid(row=0, column=0, sticky="ns")
txt_edit.grid(row=0, column=1, sticky="nsew")
window.mainloop()
#
Вот код, с помощью которого я пытаюсь построить свою тепловизионную камеру amg8833. Когда я пытаюсь поместить его в середину окна, он говорит мне,что,, Не может использовать пакет geometry manager внутри». Я пробовал по-разному, но никогда не работал с интерполяцией в реальном времени, просто изображение застревало с первого взгляда.