如何为 python 程序创建自定义 GUI? [英] How to create a custom GUI for a python program?

查看:46
本文介绍了如何为 python 程序创建自定义 GUI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为具有自定义设计的 Python 程序创建一个 GUI,我在 Photoshop 中有一个模型,我正在寻找一个支持主题的库或任何其他可以完成这项工作的库.

I want to create a GUI for a python program with a custom design, I have a mock-up in Photoshop and I'm looking for a library that supports theme or any other library that can do the job.

我的 GUI 设计包含渐变、边框、边框半径以及带有自定义最小化和关闭按钮的自定义标题栏,例如查看 Windows 版 Github 客户端,或任何 Adob​​e 软件安装程序.

My GUI design contains gradients, borders, border radius, and a custom title bar with custom minimize and close buttons, for example take a look at the Github client for Windows, or any Adobe software installer.

我尝试过 wxPython,我使用 style=wx.NO_BORDER 删除了标题栏和 Windows 添加的默认边框,但我觉得我没有使用正确的工具来完成这项工作,并且我在某处读到 wxPython 主要用于本机外观 GUI 而不是用于这种定制,所以我应该寻找其他东西.

I tried wxPython, I used style=wx.NO_BORDER to remove the title bar and the default border added by Windows, but I feel like I'm not using the right tool for this job and I read somewhere that wxPython is mainly for native look GUI's and not meant for this kind of customization so I should look for something else.

我在这里找到了一个答案,建议使用 PyQT 和 QML 在 GUI 中进行高度自定义,但编译后的文件非常大.

I found an answer here recommending the use of PyQT and QML to make high customization in GUI's, but the compiled file have a very large size.

那么我应该使用什么来创建自定义 GUI 呢?我也想编译这个程序,所以我需要用一个合理的文件大小来完成.

So what should I use to create a custom GUI ? I'm looking to compile the program too so I need to do it with a reasonable file size.

推荐答案

您最初使用 wxPython 的方法很好,您只需要为顶部 wx.Frame 设置几个样式标志:

Your initial approach with wxPython is fine, you just need a couple more style flags for your top wx.Frame:

wx.NO_BORDER ^ wx.SYSTEM_MENU ^ wx.MINIMIZE_BOX ^ wx.MAXIMIZE_BOX ^ wx.CLOSE_BOX

这不仅会删除边框,还会删除系统菜单和最小/最大/关闭框.

Which will not only remove the border but the system menu and min/max/close boxes as well.

然后直接在顶部框架的客户区域上绘制您的 gui 背景.请参阅此教程:并注意wx.DeviceContext 支持绘制位图和渐变填充.

Then paint your gui background directly on the client area of your top frame. See this tutorial: and notice that wx.DeviceContext supports painting bitmaps and gradient fills.

现在制作您的自定义按钮并让它们在点击时发布 wx.CloseEventwx.IconizeEventwx.MaximizeEvent 事件.使用绝对定位或 Sizer 将它们放在您的自定义框架上.完成.

Now make your custom buttons and have them post wx.CloseEvent, wx.IconizeEvent, and wx.MaximizeEvent events when clicked. Lay them out on your custom frame using either absolute positioning or a Sizer. Done.

这篇关于如何为 python 程序创建自定义 GUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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