如何为独立的 Python GUI 创建漂亮的 UI
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44455257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create beautiful UI's for standalone Python GUI's
提问by Eren Ar?c?
I wonder how couls I create beautiful UI's for my python GUI.
我想知道如何为我的 Python GUI 创建漂亮的 UI。
Something like this:
像这样的东西:
Or like this:
或者像这样:
How can I do that? Could I use JS frameworks like Electron?
我怎样才能做到这一点?我可以使用像 Electron 这样的 JS 框架吗?
回答by scotty3785
Best options I've seen for 'pretty' GUIs with python is Kivy, see the gallery of examples
我见过的使用 Python 的“漂亮”GUI 的最佳选择是 Kivy,请参阅示例库
回答by Daniel
Hi it looks like what you are asking is EXACTLY what pysciter is targetting. The only caveat is the fact that this is still new and possibly a bit green
嗨,看起来您要问的正是 pysciter 的目标。唯一需要注意的是,这仍然是新的,可能有点绿色
回答by ZackBoi
Like what people have already said, it depends on what you are trying to put inside of your GUI and where you want to put it. But, all of the other GUI programs that others have suggested were hard for me to download and downright difficult to learn. I assume you have used tkinter before (which has disappointing aesthetics), and are unwhelmed by the format of the premade button, entry, and other widgets.
就像人们已经说过的那样,这取决于您尝试在 GUI 中放入的内容以及想要放置的位置。但是,其他人建议的所有其他 GUI 程序对我来说都很难下载,而且很难学习。我假设您以前使用过 tkinter(它的美学令人失望),并且对预制按钮、条目和其他小部件的格式不感兴趣。
What I recommend doing is not downloading other libraries and software, but rather sticking with tkinter and only using label widgets and the bind function, which is detailed here. What the bind function allows you to do is call an action (function) when a mouse click, keyboard entry, etc... occurs over a certain widget. Essentially, you can make a button by binding the mouse click action with a label. Whenever you click on the label in the GUI, the function is called, however, now you don't have the ugly border around the text and it looks nicer. Similarly, you don't have to use the entry widget, you can bind a keyboard event over an empty label. Then inside your code, you can add whichever keyboard letter/number you press into the stringvar that control the text in the label. The list goes on and on, but essentially you would be using only labels, frames, and canvas' with the bind function to make cooler looking GUI's.
我建议这样做是不是下载其他的库和软件,但Tkinter的,而坚持,只有使用标签控件和绑定功能,这是详细这里. bind 函数允许你做的是当鼠标点击、键盘输入等发生在某个小部件上时调用一个动作(函数)。本质上,您可以通过将鼠标单击操作与标签绑定来制作按钮。每当您单击 GUI 中的标签时,都会调用该函数,但是,现在文本周围没有丑陋的边框,看起来更漂亮了。同样,您不必使用条目小部件,您可以在空标签上绑定键盘事件。然后在您的代码中,您可以将您按下的任何键盘字母/数字添加到控制标签中文本的 stringvar 中。这个列表不胜枚举,但本质上,您将只使用带有绑定功能的标签、框架和画布来制作更酷的 GUI。
Here's an example of how I made a nicer looking radiobutton grid...
With this, I can customize the size of the circles to match the size of the text, change the color of the selected and unselected circles, and change the spacing between the text and the button circles.
有了这个,我可以自定义圆圈的大小以匹配文本的大小,更改选中和未选中圆圈的颜色,以及更改文本和按钮圆圈之间的间距。
回答by user8128255
It depends where you want to use these dashboards, for device independent applications for IoT stuff (like Raspberry Pi), I would prefer Thingsboardas its opensource. Otherwise if you don't care about Losantis also a good choice.
But as scotty3785 mentioned, for not webbased applications Kivyis a very good choice.
But it just depends on your case what you choose.
这取决于您想在何处使用这些仪表板,对于 IoT 东西(如 Raspberry Pi)的设备独立应用程序,我更喜欢Thingsboard作为其开源。否则如果你不在意Losant也是不错的选择。但是正如 scotty3785 提到的,对于非基于 Web 的应用程序,Kivy是一个非常好的选择。
但这取决于您的情况,您选择什么。