是的,您需要创建一个方法来更新值,并使用after将该方法添加到tkinter主循环中。我建议用其他名称命名它,因为update已经是一个tkinter方法。在
作为一个完全未经测试的猜测:class Screen(tk.Frame):
def __init__(self, ADC, parent, controller):
tk.Frame.__init__(self, parent)
self.ADC = ADC
lbl = ttk.Label(self, text = "Test Display", background = "grey")
lbl.grid(column = 7, row = 8)
self.lblTestDisplay = ttk.Label(self, foreground = "lime", background = "black")
self.lblTestDisplay.grid(column = 7, row = 9, sticky = "ew")
self.adc_update() # start the adc loop
def adc_update(self):
displayText = self.ADC.ReadValues() #this method returns a list of values
for i in range(len(displayText)):
displayText[i] = round(displayText[i], 2)
self.lblTestDisplay.config(text = str(displayText)) # update the display
self.after(1000, self.adc_update) # ask the mainloop to call this method again in 1,000 milliseconds
注意,我还将标签创建分成两行,一行初始化,一行布局。你拥有它的方式是非常糟糕的;它会导致变量赋值给None,从而导致bug。在
最后
以上就是鳗鱼小虾米最近收集整理的关于python多久更新一次_Python Tkinter,每秒钟更新一次的全部内容,更多相关python多久更新一次_Python内容请搜索靠谱客的其他文章。
发表评论 取消回复