纯Python gui 库?

发布于 2024-07-25 18:42:24 字数 1430 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

秋叶绚丽 2024-08-01 18:42:24

从 Python 2.7 和 3.1 开始,Tk 看起来会好很多。

http://docs.python.org/dev /whatsnew/2.7.html#ttk-themed-widgets-for-tk

“Tcl/Tk 8.5 包含一组主题小部件,它们重新实现基本 Tk 小部件,但具有更可定制的外观,因此可以更相似本机平台的小部件集最初称为 Tile,但在添加到 Tcl/Tck 版本 8.5 后被重命名为 Ttk(“主题 Tk”)。

starting in Python 2.7 and 3.1, Tk will look a lot better.

http://docs.python.org/dev/whatsnew/2.7.html#ttk-themed-widgets-for-tk

"Tcl/Tk 8.5 includes a set of themed widgets that re-implement basic Tk widgets but have a more customizable appearance and can therefore more closely resemble the native platform’s widgets. This widget set was originally called Tile, but was renamed to Ttk (for “themed Tk”) on being added to Tcl/Tck release 8.5."

深爱成瘾 2024-08-01 18:42:24

最省力、效果最好的方法是了解如何使用现有的 GUI 库来部署应用程序。

The path of least effort and best results would be to learn what it takes to deploy an app using those existing GUI libraries.

忱杏 2024-08-01 18:42:24

Tkinter 是 python 标准发行版的一部分,并且默认安装。 期望在所有首先有图形显示的 python 安装中找到它。

Tkinter is part of the python standard distribution and is installed by default. Expect to find this on all python installs where there is a graphical display in the first place.

阳光下的泡沫是彩色的 2024-08-01 18:42:24

“纯 python gui 库”的概念是错误的,因为最终你将使用系统级调用和小部件,可能通过 ctypes,但这并不能改变这样一个事实:如果你开始实现你的想法,你最终将成为 wxPython

Notion of "pure python gui library" is wrong because ultimately you will be using system level calls and widgets, may be thru ctypes but that doesn't change the fact that if you start implementing your idea you will eventually become wxPython

后知后觉 2024-08-01 18:42:24

主要的错误在于它正在重新发明 GTK、Tk、Wx、QT 等制造商已经做过的轮子。 虽然纯 python GUI 在技术上是可行的,并且诸如 anygui 之类的项目确实尝试过类似的事情,但相对而言,没有什么可以实现的。通过这样做获得收益。

本机工具包还将更好地涵盖底层平台(本机对话框等)之间的差异。 这意味着该工具包允许您编写一个可移植的应用程序,该应用程序几乎不需要特定于平台的代码 - 其中大部分是由底层工具包抽象的。

Windows 上的 py2exe 等分发机制和任何 Linux 方法都允许您将 DLL 与应用程序捆绑在一起,因此您可以制作一个安装程序,将其所需的任何本机组件放入到位。 但是,实际上并没有通用的跨平台方法来执行此操作,因此您需要为每个平台维护单独的安装程序。

Principally what's wrong is that it's reinventing wheels that have already been done by the makers of GTK, Tk, Wx, QT and their ilk. While a pure python GUI is technically feasible, and projects such as anygui did attempt something similar, there is relatively little to gain by doing this.

The native toolkits will also do a better job of covering the differences between the underlying platforms (native dialogs etc.). This means that the toolkits allow you to write a portable application that needs little if any platform specific code - most of this is abstracted by the underlying toolkit.

Distribution mechanisms such as py2exe on windows and any of the linux methods allow you to bundle DLLs with the application, so you can make an installer that drops any native components it needs into place. However, there isn't really a generic cross-platform way to do this so you will need to maintain separate installers for each platform.

盛夏已如深秋| 2024-08-01 18:42:24

一方面,所有这些库都使用不同的抽象,因此任何与所有这些库一起使用的东西都可能最终支持一组最小公分母的功能,或者需要做很多工作才能使用每一个都充分发挥。

For one thing, all those libraries use different abstractions, so anything that worked with all of them is likely to wind up supporting a least-common-denominator set of functionality, or doing a LOT of work to use each to its fullest.

情话已封尘 2024-08-01 18:42:24

不太确定“重量级”是什么意思。

wx 在每个平台上都使用本机控件,并且在 Python 中使用起来就像我想象的一样容易; 毕竟,GUI API 很复杂,因为 GUI 可能会变得复杂。

我认为 wx,对于构建窗口所需的努力以及屏幕上显示的内容的质量来说,是很棒的。 我认为你不可能独自推出更好的东西。

Not really sure what you mean by "heavyweight."

wx uses native controls on each platform, and is about as easy to use in Python as I can imagine; after all, GUI APIs are complex because GUIs can get complex.

I think wx, for the effort required to build a window and the quality of what shows up on screen, is great. I don't think you're likely to roll something better on your own.

唱一曲作罢 2024-08-01 18:42:24

我认为这不是发明轮子。 它会起作用,但你为什么要这样做呢? 你提到的所有 GUI 库都是稳定的并且或多或少是防弹的。

我可以想象有一些实验实现了纯 python 库。 但我从未见过。 关于 GUI 的一切都是艰苦的工作,纯 Python 库不会有如此多的受众。

I think it's about not inventig the wheel. It would work, but why should you do that? All the GUI libraries you mentioned are stable and more or less bullet proofen.

I could imagine that there are some experiments implementing a pure python library. But I never saw one. Everything about GUIs is hard work and a pure python library wouldn't have such a big audience.

上课铃就是安魂曲 2024-08-01 18:42:24

围绕 tkinter 的轻量级包装怎么样,这样它就不需要大量设置? PySimpleGUI 构建在 tkinter 之上,这意味着它可以在 tkinter 运行的任何地方运行。

与 tkinter 相比,使用它的优势在于所需的代码量。 PySimpleGUI 程序往往非常紧凑。

下面是一个示例,显示使用许多可用小部件的自定义布局。

输入图片此处的描述

生成它的代码位于最后。 它可能看起来有很多代码,但仅此而已。 要做同样的事情需要一页又一页的 tkinter 代码。

import PySimpleGUI as sg

sg.ChangeLookAndFeel('GreenTan')
# ------ Menu Definition ------ #
menu_def = [['&File', ['&Open', '&Save', 'E&xit', 'Properties']],
            ['&Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
            ['&Help', '&About...'], ]
# ------ Column Definition ------ #
column1 = [[sg.Text('Column 1', background_color='lightblue', justification='center', size=(10, 1))],
           [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')],
           [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2')],
           [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3')]]

layout = [
    [sg.Menu(menu_def, tearoff=True)],
    [sg.Text('(Almost) All widgets in one Window!', size=(30, 1), justification='center', font=("Helvetica", 25), relief=sg.RELIEF_RIDGE)],
    [sg.Text('Here is some text.... and a place to enter text')],
    [sg.InputText('This is my text')],
    [sg.Frame(layout=[
    [sg.Checkbox('Checkbox', size=(10,1)),  sg.Checkbox('My second checkbox!', default=True)],
    [sg.Radio('My first Radio!     ', "RADIO1", default=True, size=(10,1)), sg.Radio('My second Radio!', "RADIO1")]], title='Options',title_color='red', relief=sg.RELIEF_SUNKEN, tooltip='Use these to set flags')],
    [sg.Multiline(default_text='This is the default Text should you decide not to type anything', size=(35, 3)),
     sg.Multiline(default_text='A second multi-line', size=(35, 3))],
    [sg.InputCombo(('Combobox 1', 'Combobox 2'), size=(20, 1)),
     sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85)],
    [sg.InputOptionMenu(('Menu Option 1', 'Menu Option 2', 'Menu Option 3'))],
    [sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3)),
     sg.Frame('Labelled Group',[[
     sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=25),
     sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=75),
     sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10),
     sg.Column(column1, background_color='lightblue')]])],
    [sg.Text('_' * 80)],
    [sg.Text('Choose A Folder', size=(35, 1))],
    [sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'),
     sg.InputText('Default Folder'), sg.FolderBrowse()],
    [sg.Submit(tooltip='Click to submit this form'), sg.Cancel()]]

window = sg.Window('Everything bagel', default_element_size=(40, 1), grab_anywhere=False).Layout(layout)
button, values = window.Read()

How about a lightweight wrapper around tkinter so that it doesn't require a lot of setup? PySimpleGUI is built on top of tkinter which means it runs everywhere tkinter runs.

The advantage over using it versus tkinter is the amount of code that is required. The PySimpleGUI programs tend to be really compact.

Here is an example showing a custom layout using many of the available widgets.

enter image description here

The code to generate it is at the end. It may look like a lot of code, but that's it. It would take pages and pages and pages of tkinter code to do the same thing.

import PySimpleGUI as sg

sg.ChangeLookAndFeel('GreenTan')
# ------ Menu Definition ------ #
menu_def = [['&File', ['&Open', '&Save', 'E&xit', 'Properties']],
            ['&Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
            ['&Help', '&About...'], ]
# ------ Column Definition ------ #
column1 = [[sg.Text('Column 1', background_color='lightblue', justification='center', size=(10, 1))],
           [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')],
           [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2')],
           [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3')]]

layout = [
    [sg.Menu(menu_def, tearoff=True)],
    [sg.Text('(Almost) All widgets in one Window!', size=(30, 1), justification='center', font=("Helvetica", 25), relief=sg.RELIEF_RIDGE)],
    [sg.Text('Here is some text.... and a place to enter text')],
    [sg.InputText('This is my text')],
    [sg.Frame(layout=[
    [sg.Checkbox('Checkbox', size=(10,1)),  sg.Checkbox('My second checkbox!', default=True)],
    [sg.Radio('My first Radio!     ', "RADIO1", default=True, size=(10,1)), sg.Radio('My second Radio!', "RADIO1")]], title='Options',title_color='red', relief=sg.RELIEF_SUNKEN, tooltip='Use these to set flags')],
    [sg.Multiline(default_text='This is the default Text should you decide not to type anything', size=(35, 3)),
     sg.Multiline(default_text='A second multi-line', size=(35, 3))],
    [sg.InputCombo(('Combobox 1', 'Combobox 2'), size=(20, 1)),
     sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85)],
    [sg.InputOptionMenu(('Menu Option 1', 'Menu Option 2', 'Menu Option 3'))],
    [sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3)),
     sg.Frame('Labelled Group',[[
     sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=25),
     sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=75),
     sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10),
     sg.Column(column1, background_color='lightblue')]])],
    [sg.Text('_' * 80)],
    [sg.Text('Choose A Folder', size=(35, 1))],
    [sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'),
     sg.InputText('Default Folder'), sg.FolderBrowse()],
    [sg.Submit(tooltip='Click to submit this form'), sg.Cancel()]]

window = sg.Window('Everything bagel', default_element_size=(40, 1), grab_anywhere=False).Layout(layout)
button, values = window.Read()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文