在同一类的另一个方法内定义的标签上显示一个方法的数据-python tkinter

时间:2019-07-04 13:16:54

标签: python tkinter

我正在使用python tkinter开发GUI。当我使用多线程时,来自一个工作线程的数据将通过Queue访问。我有一种开发GUI的方法,还有另一种处理传入数据的方法。我想在GUI上的标签上显示传入的数据。我能够打印数据,但是如何使用'textvariable'和StringVar分配数据。 ??

class GuiPart:
    def __init__(self, master, queue, endCommand):
        self.queue = queue
        # Set up the GUI
        console = tkinter.Button(master, text='Done', command=endCommand)
        console.pack()
        self.output= ''
        output = tkinter.StringVar()
# I want to set this output with incoming data and assign to textvaribale.
# incoming data is in the next method processIncoming

   ##---output.set(1)testing

        output_1_label = tkinter.Label(master, textvariable= output, height=2, width=12)
        output_1_label.pack()
        # Add more GUI stuff here

    def processIncoming(self):
        """
        Handle all the messages currently in the queue (if any).
        """
        self.output.set(1)
        while self.queue.qsize():
            try:
                msg = self.queue.get(0)

                # As a test, I simply print it
                print (msg)
#here i want to assign it to output variable.. How? 
#self.output.set(msg) ???
            except queue.Empty:
                pass


0 个答案:

没有答案