내장 된 Python GUI Tkinter로 프로그램을 프로토 타이핑하고 동시에 여러 라벨을 업데이트하려고 할 때 문제가 있습니다. GUI는 몇 가지 새로 고침을 처리 할 수 있지만 10 초 정도 지나면 멈 춥니 다. 나는 각 레이블이 다른 센서 데이터를 표시하기 때문에 모든 레이블을 동시에 거의 동시에 업데이트해야합니다.python - 여러 라벨을 동시에 업데이트 할 때 Tkinter가 응답하지 않음
지금은 random
모듈을 사용하여 실제 데이터 대신 숫자를 생성합니다. 동시에 10 개 정도의 레이블이 있으므로, tkinter가이를 처리 할 수 있는지 확인하고 싶습니다. 레이블은 초 단위로 업데이트됩니다 (약 200 밀리 초). 나는 창에서 파이썬 3.3을 사용하고있다.
몇 가지 옵션에 대해 읽었지만 tkinter에는 익숙하지 않습니다. 링크 : 나는 Here. And Here.
멀티 스레딩 고려 하는가? 다중 처리? 나는 어느 경험도 가지고 있지 않지만 이것을 해결할 뜻이 있다면 배울 의향이있다.
tkinter
으로도 내가 뭘하려하고 있습니까? pygame
또는 다른 GUI를 사용해야합니까? 내가 여기서 무엇을 놓치고 있니? 내가 여기에 생각
import random
from tkinter import *
class Application(Frame):
"""The GUI window"""
def __init__(self, master):
"""Setup the Frame"""
super(Application, self).__init__(master)
self.grid()
self.setupWidgets()
self.update()
def setupWidgets(self):
"""Setup widgets for use in GUI"""
#setup data readings
self.data_lbl_txt = "Data Readings"
self.data_lbl = Label(self, text = self.data_lbl_txt)
self.data_lbl.grid(row = 0, column = 1, columnspan = 2, sticky = E)
#setup first data piece
self.data1_txt = "First piece of data:"
self.data1_lbl = Label(self, text = self.data1_txt)
self.data1_lbl.grid(row = 1, column = 1, sticky = W)
self.data1 = StringVar()
self.data1_Var = Label(self, textvariable = self.data1)
self.data1_Var.grid(row = 1, column = 2, sticky = W)
#setup second data piece
self.data2_txt = "Second piece of data:"
self.data2_lbl = Label(self, text = self.data2_txt)
self.data2_lbl.grid(row = 2, column = 1, sticky = W)
self.data2 = StringVar()
self.data2_Var = Label(self, textvariable = self.data2)
self.data2_Var.grid(row = 2, column = 2, sticky = W)
def update(self):
self.data1.set(random.randint(1,10))
self.data1_Var.after(200, self.update)
self.data2.set(random.randint(1,10))
self.data2_Var.after(200, self.update)
root = Tk()
root.title("Data Output")
root.geometry("600x250")
window = Application(root)
window.mainloop()
Tkinter는 10 개의 라벨 업데이트를 쉽게 처리 할 수 있습니다. –