在python中将进度值发送到进度条

2024-03-29

在我的游戏中我有两个模块,岛.py它将岛屿加载到我的游戏中,第二个模块是gui.py它在游戏开始之前处理 GUI 小部件。我的问题是如何将 island.py 模块中的进度值发送到中创建的进度栏gui.py module 编辑:还可以使用加载屏幕的实例来访问其中的进度栏​​并更改其值。

在模块 island.py 中

def __iter__(self):
        total = float(len(self.ground_map))
        import game.gui
        for i in self.get_coordinates():
            yield i
            global count
            count+=1
            progress = (count/total) * 100 
            game.gui.Gui.set_progress(progress)
        global count
        count = 0

在模块 gui.py 中

def show_loading_screen(self):
    self._switch_current_widget('loadingscreen', center=True, show=True) # Creates the loading screen and its associated widgets, except the progress bar.

@staticmethod
def set_progress(progress):
    # Now I have the progress values, and it will be updated automatically... how can I pass it to the progress bar widget?
    # I need to create the progress bar widget here, but to do that I need to have the self instance to give me the current screen that I will create the progress bar for **AND HERE IS THE PROBLEM!!**
    def update_loading_screen(progress):
        """updates the widget."""
        **self,current**.findChild(name="progressBar")._set_progress(progress)
    update_loading_screen(progress)

我怎样才能使这个 update_loading_screen 功能?


扩展rocksport的答案......这就是我所做的

class GUI:
    def __init__(self):
        GUI.self = self


    @staticmethod
    def set_progressbar():
        print "set progress bar"
        print GUI.self


g = GUI()
g.set_progressbar()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在python中将进度值发送到进度条 的相关文章

随机推荐