Python:如何从GTK +类实例中的另一个类实例访问属性

问题描述

以下是MWE-当然当然还不能使用:-)

如何获取gtk标签,以将其从流式类连续更改(更新)为值“ count”?

我知道,无需两个单独的类即可完成此操作,但实际上,流类将读取串行数据,并且我想将其与gtk循环分开。

我知道关于SO的类似问题,但这些问题与GTK的类实例无关

import gi
gi.require_version('Gtk','3.0')
from gi.repository import Gtk
import threading


class mainWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self,title="Welcome to GNOME")
        self.set_default_size(800,600)

        label = Gtk.Label("Hello World")
        self.add(label)
        self.show_all()
    
class streaming():
    def __init__(self):
        
        self.count = 0
        
        thread = threading.Thread(target=self.stream)
        thread.daemon = True
        thread.start()
    
    def stream(self):
        while True: # This runs/loops in a separate thread to GUI
            self.count = self.count + 1
            print(self.count)


if __name__ == "__main__":
    mon = streaming()
    app = mainWindow()
    Gtk.main()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)