views:

1040

answers:

8

Hello.

Python has a lot of gui librarys: tknter, wxWidgets, pyGTK etc. But all this gui needs to be installed and quite heavyweight, so it's a bit complex to deploy end-user gui python apps that relay on mentioned gui librarys.

Recently, i have thinked about python build-in ctypes. Theoretically, it's possible to create 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 library exists? If not, how do you think what's wrong with an idea?

+1  A: 

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.

Gregor
+6  A: 

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

Craig McQueen
+1: "quite heavyweight" is an overstatement. In most cases, you need all of that to build a GUI.
S.Lott
+2  A: 

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.

Hank Gay
+3  A: 

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.

John Pirie
+6  A: 

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.

TokenMacGuy
+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...
e-satis
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 http://stackoverflow.com/questions/349409/why-are-tk-guis-considered-ugly
Bryan Oakley
Tkinter is installed by default only on windows and macos. It need to be installed on ubuntu etc.
Eye of Hell
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.
TokenMacGuy
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.
Warren P
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 (http://www.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.
TokenMacGuy
+2  A: 

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

Anurag Uniyal
+3  A: 

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.

ConcernedOfTunbridgeWells
+3  A: 

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

Corey Goldberg