【发布时间】:2011-04-12 22:45:47
【问题描述】:
在我的游戏中,我有两个模块,island.py 将岛屿加载到我的游戏中,第二个模块是 gui.py,它在游戏前处理 gui 小部件开始。我的问题是如何将 island.py 模块中的进度值发送到在 gui.py 模块中创建的进度条 编辑:还使用加载屏幕的实例来访问进度条并更改其值。
在模块 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 功能?
【问题讨论】:
-
你真的应该把所有的导入语句放在最前面,除非你动态导入模块。
标签: python user-interface loading progress