9

I wanted to say "best python GUI compared to Swing"... but was sternly told my question was "too subjective". I apologise to the deterministic ghost in the machine.

I'm currently using Jython... have been using it for maybe 6 months now following years of Java. I love Jython's ability to call on all the Java classes, and also to ease the transition from a Java way of doing things to a Python way.

But thinking about it I realise that by far the most common Java packages I'm using are the Swing ones. I have spent many years wrestling with Swing and finally think I have the beast under some kind of body-lock. I also think Swing is wonderful, by the way, and I have to say that I am something of a keyboard fanatic, for example, so wouldn't want to switch to a GUI where you don't have power akin to that lurking in ActionMap-InputMap, which maybe not many people care that much about. It would also be a shame really to turn my back on JTree and JTable, having spent so much time tearing out what was left of my hair about them. Seriously, they are fiendishly powerful...

But at the same time I'm fast becoming hooked on the Python way of doing things. I can and intend to stick with Jython. But I was just wondering what the various CPython GUIs are like... and specifically how their power and versatility compare with Swing?

added: I have been asked to provide some specifics: OK, what about a tree GUI object sitting on a scroll pane where it is possible, if you want to, to control navigation and collapsing/expanding of nodes using the keyboard... where the scrolling happens automatically (if you want it to) and where you have control over look and feel, etc. Or tables where you have comprehensive control over resizing, over what happens when individual cells gain/lost focus. Where you can subclass renderers and editors. As I said in my comment, someone who is/was keen on, and a big user of, Swing but nonetheless made a transition to a CPython GUI and was happy/unhappy... might be the ideal person to answer this.

mike rodent
  • 14,126
  • 11
  • 103
  • 157
  • possible duplicate of http://stackoverflow.com/questions/93930/what-python-gui-apis-are-out-there – jterrace Oct 17 '11 at 19:18
  • This question is still basically a very vague "shopping recommendation" one - I don't see how it's *answerable*. To salvage it, try adding some *specific* constraints on what you want / need from a GUI toolkit. "Powerful" isn't a very clear or objective metric. (I find Swing has lots of glaring omissions and questionable design choices for instance.) – millimoose Oct 17 '11 at 19:22
  • There is no "ghost in the machine", but there is a FAQ that explicitly states what types of questions NOT to ask: "You should only ask practical, answerable questions based on actual problems that you face. Chatty, open-ended questions diminish the usefulness of our site and push other questions off the front page." – Dave Oct 17 '11 at 19:22
  • @jterrace thanks for that... obviously I did a search... but I couldn't find an informed, specific comparison between the power of Swing and the power of python GUIs. Humbly request my question be allowed to stand (for a bit)... – mike rodent Oct 17 '11 at 19:23
  • @Inerdia - OK, well there's a chap called Hanya who is something of an OpenOffice/Jython/Python genius... and he wrote an introspection tool called MRI for inspecting OpenOffice objects... but it's written in Python and from a GUI standpoint it's not impressive: there is no use of resizable columns as per JTable, or automatic scroll bars as per JScrollPane... which is not to say these things can't be done. Ideally I'd like an answer from a very keen user of Swing who has switched to a Python GUI – mike rodent Oct 17 '11 at 19:26
  • @Dave just because someone hasn't been that involved with this site doesn't mean they are stupid or naive. I think my question is a good one, particularly for users coming from Java who might be intrigued, or more, by Python. It is interesting that my Python book, Beazley, Python Essential Reference, hardly mentions GUI at all. And yet an understanding of EDT/non-EDT threads is crucial to every program with a GUI element. – mike rodent Oct 17 '11 at 19:42
  • Those who vote against the question aren't saying you're stupid or naive, but they are saying your view of when a "question is a good one" might not match up with the site in general. In particular, please make sure the question is phrased such that someone could say, unambiguously, "Yes, that's the answer to this question". – jkerian Oct 17 '11 at 20:01
  • @jkerian well personally I think the tone adopted by "Dave" was not acceptable. Secondly I question your assertion that all useful questions here, which might prove extremely useful to many, are all going to have unambiguous answers. The point is that questions like mine have to have a purpose and a necessity and I think mine has both. – mike rodent Oct 17 '11 at 20:20
  • Just to point out... he quoted the FAQ verbatim. If you see a conflict between what he stated and the question, this may not be the best site for the question. – jkerian Oct 17 '11 at 20:42
  • @jkerian LOL I know he did... but, friend, tone is determined by multiple factors, e.g. *what* you choose to quote, the *way* you choose to quote it, if at all, and your use of CAPITAL LETTERS, presumably having, intrinsically, a different tone to friendly, nice, *lower-case* letters – mike rodent Oct 17 '11 at 21:46

2 Answers2

3

I never done much with Swing, but Qt (and its bython bindings, PySide or PyQt4), matches all of your criteria as far as I can understand them.

Qt focuses on doing things as it's customary on the underlying OS. So the most obvious thing to do is usually the “right” thing to do, but if you want control you can go and override the look or behavior.

As for the pythonic way of doing things... The bindings are getting there. They still feel somewhat C++-ey, to be honest.

Also read some other questions on comparison between the two.

Community
  • 1
  • 1
Petr Viktorin
  • 65,510
  • 9
  • 81
  • 81
  • thanks... if you have a moment would you by any chance be prepared to look at this discussion on the problems of implementing a "complex tree" in PyQt... http://old.nabble.com/Looking-for-complex-tree-view-example-td16747194.html ... it is stuff like this from clearly experienced programmers which makes me hesitate before investing lots of time in learning something new like PyQt – mike rodent Oct 18 '11 at 07:03
  • Yes, with the models you need to be a bit careful: if you store a Python object in a QModelIndex, you need to make sure the object outlives the index (all these issues are caused by the fact that QModelIndex can't do Python reference counting). With dynamic models it might get tricky. Notice that this is about the *model*; the *view* functionality (resizing, collapsing/expanding, focus behavior, renderers&editors) doesn't have these issues. But of course you can't have one without the other... Try [a built-in model](http://doc.qt.nokia.com/latest/qfilesystemmodel.html) for your first tests. – Petr Viktorin Nov 03 '11 at 21:02
0

I think Python has many toolkit for GUI. Java has Swing. If you want to develop cross-platform friendly GUI,I suggest wxPython.

Masked Man
  • 522
  • 1
  • 6
  • 21