所以我正在使用 PGU 在 pygame 中制作一个应用程序。我无法弄清楚如何访问主更新循环。我有一个很好看的事件界面,但是我也有一些网络代码需要在每个循环中发生(检查服务器是否向我发送了任何东西)。如何让我的代码执行每个循环?
我在想也许在 pgu 中总会发生一些事件,如果是这样,那么我可以捕捉到这个事件,并执行我的服务器检查代码。
如果你们需要任何其他信息,请询问,如果需要,我可以发布我的代码。谢谢
Maythe has already mentioned this, but what you need to use is the app.loop function. So, say you have a function that will do everything you want to happen on top of the mainloop, called dosomething, you would do this:
myapp = gui.App()
myapp.init(widget=<your root widget>)
while True:
dosomething()
myapp.loop()
In fact, I looked at the pgu code online, and all that mainloop does is:
while True:
myapp.loop()
time.sleep(wait) #this is just a routine wait each iteration you give it
So you really are directly adding code on top of the update function, without any unwanted side effects.