Python Tkinter GUI在循环启动时冻结
我从CCD上获取数据,同时移动舞台并显示CCD上的实时更新图像。现场的情节工作,但一旦我点击开始按钮开始阶段,整个图形用户界面冻结。我想在舞台移动时从CCD上获取实时图像。如能帮助解决此问题,我们将不胜感激 循环的最小代码如下所示Python Tkinter GUI在循环启动时冻结,python,matplotlib,tkinter,tkinter-canvas,Python,Matplotlib,Tkinter,Tkinter Canvas,我从CCD上获取数据,同时移动舞台并显示CCD上的实时更新图像。现场的情节工作,但一旦我点击开始按钮开始阶段,整个图形用户界面冻结。我想在舞台移动时从CCD上获取实时图像。如能帮助解决此问题,我们将不胜感激 循环的最小代码如下所示 movepos = np.linspace(startpos,endpos,Np1) dm = movepos[1]-movepos[0] tic = time.time() act_pos = motor.position
movepos = np.linspace(startpos,endpos,Np1)
dm = movepos[1]-movepos[0]
tic = time.time()
act_pos = motor.position
def start():
global diffposvec
motor.move_to(movepos[0])
for count in range(0,Np1):
movetopos = movepos[count]
motor.move_to(movetopos)
# while motor.is_in_motion: #having this while statement makes it stop before it moves again
# toc = time.time()
# def live_spectrum2():
global framer
ax2.cla()
framer= cammer.grab_image(timeout='1s',copy=True,n_frames=1,exposure_time='5ms',cx=420,
left=200,cy=600,top=300)
ax2.imshow(framer)
canvas2.draw()
canvas2.get_tk_widget().place(x=5,y=5)
# fig_plot.after(50,live_spectrum2)
# fig_plot=tk.Frame(self)
# tk.Frame(live_spectrum2()).pack()
framer = cammer.grab_image(timeout='1s',copy=True,n_frames=1,exposure_time='5ms',
cx=420,left=200,cy=600,top=300)
heighter = np.shape(framer)[0]
widther = np.shape(framer)[1]
framemat = np.zeros((heighter, widther ,Np1))
horzmat = np.zeros((Np1,widther))
horzmat[count,:] = np.sum(framer[300:400,:],0)
act_pos = motor.position
diffpos = movetopos-act_pos
diffposvec = []
diffposvec = np.append(diffposvec,diffpos)
if np.mod(count,10)==0:
print('Step number %.0f' % (count+1),' of %.0f' % Np1, ' %.4f s' % (tic),' %.3f um' % (act_pos*1000),' %.3f um' % (movetopos*1000),' %.3f nm' % (diffpos*1e6))
start_btn=Button(self,text="START",font=(NormalFont,'16'),height=36,borderless=5,
foreground="#161327",background="#707087",
command=lambda: start())
start_btn.place(x=350,y=650)
在循环中,Tkinter无法更新屏幕。已经有人问过了,也许其中一个能帮你?您可能需要执行某种类型的多线程。您只需在
循环的开始处添加root.update()
,而循环谢谢,您能否提供一个实例,说明如何对实时更新绘图使用线程选项(以便GUI不会冻结)?