Pure python gui library? [closed]
Asked Answered
D

9

8

Python has a lot of GUI libraries: tkinter, wxWidgets, pyGTK etc. But all these GUIs need to be installed and quite heavyweight, so it's a bit complex to deploy end-user GUI python apps that relay on mentioned GUI libraries.

Recently, I have thought about python's built-in ctypes module. Theoretically, it's possible to create a pure python GUI library that will use ctypes on windows ( windll.user32.CreateWindowEx, etc ), native pyObjC on MacOS and pyGTK / pyQt on gnome / kde. Does such a library exist? If not, what do you think is wrong with this idea?

Doviedow answered 24/6, 2009 at 10:58 Comment(5)
Tkinter doesn't need to be installed, it's part of a standard distribution of python.Indulgent
Only on windows and macos. It need to be installed on ubuntu etc.Doviedow
you mean something like "rewrite wx in python"? Why do you think it would be better than what's already been done?Keshiakesia
Will not require installation and can be supplied as a part of script.Doviedow
If portability is a priority, it would almost certainly be less hassle to bundle your library somehow or use Py2Exe to build a standalone executable, than to rewrite an entire GUI framework from scratch.Bronwyn
E
10

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

Eudora answered 24/6, 2009 at 11:14 Comment(1)
+1: "quite heavyweight" is an overstatement. In most cases, you need all of that to build a GUI.Dixon
I
11

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."

Interscholastic answered 24/6, 2009 at 13:48 Comment(0)
E
10

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

Eudora answered 24/6, 2009 at 11:14 Comment(1)
+1: "quite heavyweight" is an overstatement. In most cases, you need all of that to build a GUI.Dixon
C
8

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.

Cand answered 24/6, 2009 at 11:45 Comment(6)
+1. If you need more widget, there are some adds on and plugins for TKinter that are lightweight and will improve the toolkit dramatically. But, still, the UI is ugly...Hen
The "ui is ugly" comment mostly only applies to old versions of Tkinter. Modern Tk uses native widgets on platforms that support it. Ugly Tkinter applications these days is mostly a reflection of programmer talent rather than toolkit limitations. For more on that discussion see #349909Indulgent
Tkinter is installed by default only on windows and macos. It need to be installed on ubuntu etc.Doviedow
To clarify. In its default configuration, Python will attempt to use tk, if it is available. Binary distributions besides the mainline, such as Ubuntu or red-hat or whatever may follow a different policy. Most often this will be to break up the standard python library based on its external dependencies, so you don't have to pay for tens or hundreds of megs of library code you won't actually use.Cand
I guess I'm one of those guys who remembers the Ugly Old TK thing. Maybe I only think the inside of TK is ugly now. Maybe I'm just a bigot, and need to have another look. I never understood why Python has always been saddled with the most gronky of all GUI toolkits built in.Cookshop
Probably the reason why python picked Tk is that at the time, there were no other mature, cross platform toolkits. Tk was usable all the way back to 1990 (tcl.tk/about/history.html), many years before any reasonable alternative was available. Also unlike other early toolkits, it was meant to be used embedded in an interpreted language, and so porting it to python would be much easier than binding another C oriented toolkit.Cand
N
6

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

Neurath answered 24/6, 2009 at 13:15 Comment(0)
S
5

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.

Sickler answered 24/6, 2009 at 13:24 Comment(0)
K
4

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.

Kwangchowan answered 24/6, 2009 at 11:18 Comment(0)
C
4

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.

Crazy answered 24/6, 2009 at 11:36 Comment(0)
S
2

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.

Sladen answered 24/6, 2009 at 11:8 Comment(0)
T
1

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()
Trocki answered 3/9, 2018 at 23:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.