程序的主循环是否可以移出GUI? [英] Can the main loop of a program be moved out of GUI?

查看:129
本文介绍了程序的主循环是否可以移出GUI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在查看代码示例时,我注意到主循环通常在代码的GUI部分,而其余​​的代码提供了GUI需要时调用的回调。



但我的模拟独立于用户交互运行; UI在那里提供了一个视图,不时地,在模拟中发生了什么,但它不能控制模拟中发生了什么。所以我想主循环是关注模拟而不是UI。我该怎么做?

解决方案

为什么不分开你的逻辑和演示文稿。编写你的sim后端来回应一个基于文本的protcol来接收cmds并发送结果,然后再通过你的gui程序与它进行比较。 unix套接字。


I'm using python 3 / tkinter if that matters.

In looking at code samples I noticed that the main loop is typically in the GUI part of the code, and the rest of the code provides callbacks for GUI to call when needed.

But my simulation runs independently of the user interaction; the UI is there to provide a view, from time to time, into what's going on in the simulation, but it doesn't control what goes on in the simulation. So I would like the main loop to be concerned with the simulation rather than UI. How would I do that?

解决方案

Why not seperate your logic and presentation. Write your sim backend to respond to a single text based protcol to receive cmds and send back results, and then just talk to it from your gui program over e.g. unix sockets.

这篇关于程序的主循环是否可以移出GUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆