如何在 Kivy 中拥有多个窗口?
问题描述
我正在尝试从完全不同的 GUI 打开一个 GUI.我正在桌面上开发,并且窗口的大小彼此不同.我查看了屏幕管理器,但感觉好像有更简单的方法可以做到这一点.
I am trying to open one GUI from a completely different GUI. I am developing on a desktop and the windows have different sizes from each other. I looked at screen manager but I feel as if there is an easier way to do this.
提前致谢!
解决方案
有可能,但有点不方便.问题是 kivy 每个应用程序仅支持一个窗口,因此您需要以某种方式解决它.我个人只是在一个窗口中使用多个 *Layouts(它们是具有不同功能的不同 GUI),并根据需要显示和隐藏它们.显然这种方法有其局限性,eg它不支持多显示器,但它很简单.
It's possible, but kinda inconvenient. The issue is that kivy supports only one window per app, so you need to work around it somehow. I personally just use multiple *Layouts (which are different GUIs with different functions) in a single window, showing and hiding them as necessary. Obviously this approach has its restrictions, eg it doesn't support multiple monitors, but it's as simple as it gets.
然后有一个问题 在这里,人们为每个窗口生成单独的 kivy 应用程序,从而获得可以相对拖动和调整大小的窗口.它需要一些子进程的摆弄和应用程序之间的通信,但这种方法更强大.
Then there is a question here on SO where people spawn separate kivy apps for every window, thus getting windows that can be dragged and resized relatively. It requires some fiddling with subprocesses and communicating between apps, but this method is more powerful.
据我所知,ScreenManager 对您没有帮助:它只允许为同一个窗口定义多个小部件树并在它们之间动态切换.这是触摸屏上的正常用例,但在桌面上几乎没有意义.老实说,这对于 kivy 中的很多事情都是正确的.如果你以后不打算转向手机,Tkinter 或 PyQT 可能是比 kivy 更好的选择.
ScreenManager, as I understand, doesn't help you: it allows just to define multiple widget trees for the same window and switch between them on the fly. It's a normal use case on touchscreens, but makes pretty little sense on desktop. Which is true for quite a few things in kivy, to be honest. If you don't plan to move to mobiles later, Tkinter or PyQT may be a better choice than kivy.
相关文章