12 ms·
Hello Qt for Python
- jimnotgym 8y agoI would love to hear more about this from the sages of HN. I really don't enjoy GUI development in Python. I am not a good enough CS to have the language to describe what is wrong, but I find it really hard to get Python GUI stuff to do what I want.
- blattimwind 8y agoIf you can't express what's wrong it will be even harder to find a solution.
- jimnotgym 8y agoSorry, I thought it was generally accepted that Python's relationship with the GUI was troubled? Put in plain English it is like this. I write quite a lot of code that integrates various enterprise systems together. Things like EDI management, and 'brokers' between incompatible API's. It is usually a mixture of Python/Bash/SQL. It is not my full-time job to code, but I get things done. As complexity increased I learned about version-control, OOP, and unit-testing. I have some pretty complex stuff in production. So I can self-learn all of those things, but not Python GUI programming The kind of thing I would happily launch from the command line, often needs a GUI when end users are involved. Even to have an app that takes an input>click OK>do some API stuff>return an answer seems absurdly complicated in Python and [insert whichever GUI framework]. In fact I find it simpler to add a web front end and a server than I do a desktop GUI. Qt was never on my list as I have enough battles to handle without negotiation with bosses for PyQt licensing costs. Hence my interest in this development. I didn't have this trouble with VB6 or VB.NET. Draw a box>draw a button>double-click the button>add the code you want to run when the button is clicked. When I do the same in Python I have dozens of lines of set-up code. I have a window with a text box and a button, surely that should be three lines of code (like in html)? Then I find that things are not running in the order I expected... Imagine for instance I want to put an alert box up that says "working", then call the function to do the work, then take the alert box away when the function exits...My Python head says this should look like this def on_ok_clicked(event): alert=framework.alertbox(text="working...") do_important_blocking_stuff() alert.destroy() and instead I find the GUI hanging while the function is running, then the alert box flash up and exit, or something equally unintuitive. There doesn't seem to be a Pythonic or indeed simple way to handle these super straight-forward use cases. I have no aspiration to be a UX person, or learn a new paradigm just to have a button that says "GO!". I'm guessing from the other comments that Qt for Python is not going to be my savior.
- toyg 8y ago> My Python head says this should look like this No, that's not "your python head", sorry, that's your "VB head" at best. That's lack of knowledge of how desktop GUI paradigms actually work and what an event loop is and how it interacts with threads. I do not disagree that VB (and Delphi) did a better job at hiding these concepts from the "just getting it done" crowd, but don't blame it on Python if you don't have a grasp of how C++ GUI toolkits actually work.
- jimnotgym 8y ago> but don't blame it on Python if you don't have a grasp of how C++ GUI toolkits actually work. I'm not blaming it on Python, honestly. I'm just really surprised that there isn't a framework that will hide that stuff from me like VB did. You are a 100% correct in that I don't know anything about desktop GUI paradigms, or C++ GUI toolkits. I really don't have the bandwidth to find out either! I'm also surprised that I need to. I don't think that is even my VB head, I am a business systems person who has successful modeled a physical process in software. In a recent case I did all of the work negotiating with vendors/management/users, I found the bugs in the vendors API, and I did this to an absurd deadline (with almost zero budget) created by a a vendor withdrawing a product with no notice. That's the kind of absurd thing us plebs in the "just getting it done" crowd have to do all of the time. But I am finding that simple GUI launchers for my software are really complicated in Python with the frameworks I have found. I am shocked that this is the piece that is defeating me! As I said before, I could write a web front-end for this kind of thing relatively easily (in the above case it was a hardware requirement that lead me to try again at the desktop GUI). Perhaps this is why we see so many people looking at the web-app-on-the-desktop that is so derided on these pages?
- mixmastamyk 8y agoYes, a shame that the FLOSS world never came up with a competitive integrated VB/Delphi clone in a better language like Python. Probably it would have been a huge undertaking, right when web dev was taking off. Although I've heard good things about Lazarus IDE, probably your best bet for such projects. Pascal is not hard to learn, or re-learn. https://en.wikipedia.org/wiki/Lazarus_(IDE) https://en.wikipedia.org/wiki/Lazarus_(IDE) http://www.lazarus-ide.org/ http://www.lazarus-ide.org/
- billsix 8y agoRetained-mode GUIs like Qt , wxWidgets, gtk, etc aren't intuitive. Try an immediate mode GUI, like my python bindings to nuklear https://github.com/billsix/pyNuklear https://github.com/billsix/pyNuklear
- btown 8y agoFor more context, immediate mode is much closer to the type of declarative UI popularized by libraries like React. The invariant is that what is displayed on screen is always a pure function of some state variable(s), and on any input/event, instead of needing to "reach into" some retained object that represents a certain piece of text in a certain pane in a certain window, you just change those state variables and re-render the entire UI from scratch. Sounds expensive, but for a 2D UI on hardware that's designed to do far more complicated things at 60FPS, it's far from the bottleneck. For instance, https://github.com/billsix/pyNuklear/blob/master/demo/overview.py#L305 https://github.com/billsix/pyNuklear/blob/master/demo/overvi... (this function is called repeatedly on each frame) is not significantly different from the example at https://reactjs.org/tutorial/tutorial.html#what-is-react https://reactjs.org/tutorial/tutorial.html#what-is-react ... but it is very different from something like `div = createDiv(); div2 = createDiv(parent=div)` etc. which would be a retained-mode API.
- billsix 8y agohttps://youtu.be/Z1qyvQsjK5Y https://youtu.be/Z1qyvQsjK5Y
- civilian 8y agoAnother option is pyImgui. Imgui is C++ based. pyimgui isn't on the latest imgui version, but it's coming along. https://github.com/swistakm/pyimgui https://github.com/swistakm/pyimgui
- vram22 8y agoWhat is the difference between the two GUI modes?
- 8y ago
- simion314 8y agoCan't you use a designer GUI to develop the static GUIs? You will have to understand how layouts actually work and how the designer translates your design into code/widgets/layouts. Then in Python you write your logic and event handlers. Qt also offers QML, if you are a fan of how those components look you may enjoy using it.
- blattimwind 8y agoQt for Python == PySide2 == PySide for Qt 5.
- cup-of-tea 8y agoI used PyQt5 quite successfully a while back. This looks very similar. What is actually new here?
- veeti 8y agoPermissive license.
- cup-of-tea 8y agoSo PyQt5 is GPL. Practically speaking what is the point of a new permissively licensed library?
- mherrmann 8y agoEg. that you can use it for free(?)
- seba_dos1 8y agoOnce upon a time, Qt was GPL + commercial. A separate project - PyQt - came and was GPL + commercial too. Later, Qt became GPL + LGPL + commercial. However, PyQt, didn't want to add LGPL and stayed dual licensed. Qt thought "ok then, will have to do it by myself" and created an alternative to PyQt called PySide, which was GPL + LGPL + commercial. That was in Qt4 time. Then Qt5 came, and PyQt5 appeared, while PySide was still in Qt4 land. Then PySide2 happened, now known as Qt for Python.
- drb91 8y agoThis seems easily googleable. Are you really completely oblivious as to controversy surrounding the GPL, especially as opposed to LGPL and ASL/MIT/BSD?
- Hamuko 8y agoAnd GPL isn't permissive.
- _wmd 8y agoPySide came to exist because Nokia failed to reach a commercial licensing agreement with Riverbank (the makers of PyQt). I guess one side or the other was asking for too much https://wiki.qt.io/PySide_FAQ https://wiki.qt.io/PySide_FAQ > Initial research into Python bindings for Qt involved speaking with Riverbank Computing, the makers of PyQt. We had several discussions with them to see if it was possible to use PyQt to achieve our goals. Unfortunately, a common agreement could not be found , so in the end we decided to proceed with PySide.
- fooker 8y agoWhat happened to PyQt? Also, the API does not seem Pythonic at all.
- craftyguy 8y agoPyQt is still around. This seems to be an 'official' thing from the Qt folks.
- mherrmann 8y ago... with a more permissive licence (Qt for Python is LGPL, PyQt is GPL or $550 per dev commercially).
- sevensor 8y agoAnd it's generally worth it. PyQt has been great, and I find the messaging from Pyside a little offputting -- "finally, Qt for Python." Pyside, you weren't there when I needed you, and now you're back and you want to pretend like we don't have history?
- Hamuko 8y agoWhen did you need it? Because PySide is not new.
- toyg 8y agoPySide didn't support Qt5. That's because the project was basically left for dead by Nokia and then Digia - for Qt proper, bindings will always be an afterthought. Meanwhile, PyQt just chugged along just fine. Riverbank must keep focusing on it all the time or it will die. The incentives are very different.
- sevensor 8y agoPySide was stuck on Qt4 and basically stalled. PySide2 is practiaclly a new project. For Qt5 bindings, PyQt has been the only game in town for years, and Riverbank has done a damn good job of it.
- std_throwaway 8y agoThis seems to be the successor for PySide that supports Qt 5. The old PySide died some years ago and only PyQt was offering Qt 5 support. Due to some details PyQt was never officially supported by Qt. Is PySide2 now officially supported by Qt?
- mherrmann 8y agoPyQt is not affiliated with Qt the company. "Qt for Python" (formerly PySide2) is. So, yes.
- Walkman 8y agoYes: https://groups.google.com/forum/#!topic/pyside-dev/pqwzngAGLWE https://groups.google.com/forum/#!topic/pyside-dev/pqwzngAGL...
- toyg 8y agoYes, but tbh even PySide was originally "officially supported" by Qt, when Nokia owned it; and then it was dropped. So the question is whether it will continue to be supported. The owners of PyQt (Riverbank) depend on that product to survive; whereas Qt has bigger fish to fry most of the time. The incentives are very different.
- mkl 8y agoIt wasn't so much that PySide was dropped, as the whole of Qt was dropped (by Nokia). PySide development was funded by Nokia, which owned Qt, and done mostly in a Nokia R&D institute in Brazil (INdT). Nokia sold Qt to Digia, and Microsoft bought Nokia, so there was no connection anymore between Qt and the people who developed PySide, and so it stalled. Digia later spun off The Qt Company, which develops Qt and is now developing PySide2, so this is actually the first time the same organisation has developed both Qt and Python bindings for it. For many purposes (including mine), PyQt is very expensive, so I'm really hoping PySide2 goes somewhere.
- msie 8y agohttp://blog.qt.io/blog/2018/04/13/qt-for-python-is-coming-to-a-computer-near-you/ http://blog.qt.io/blog/2018/04/13/qt-for-python-is-coming-to... "PySide2 – the bindings from Python to Qt – changes skin this spring. We have re-branded it as Qt for Python on a solution level, as we wanted the name to reflect the use of Qt in Python applications. Under the hood it is still PySide2 – just better."
- mherrmann 8y agoVery happy to hear this as the author of a PyQt-based file manager [1] and an open source library for solving the many headaches that come with developing desktop apps [2]. Once Qt for Python is stable enough, I'll be happy to switch to it from PyQt. [1]: https://fman.io https://fman.io [2]: https://github.com/mherrmann/fbs https://github.com/mherrmann/fbs
- deleted 8y ago[deleted]
- StavrosK 8y agoWhat would you recommend to someone who wants to write Python desktop applications today? I've used wxWindows way back when, and I'd hate to use Electron. Would you go with Qt for Python, or PyQT? Also, what's PySide/PySide2?
- traverseda 8y agoNot OP, I've been very impressed with some enlightenment apps written using python. In particular: https://github.com/DaveMDS/egitu https://github.com/DaveMDS/egitu https://phab.enlightenment.org/w/projects/python_bindings_for_efl/ https://phab.enlightenment.org/w/projects/python_bindings_fo... Scroll down to "python projects using EFL".
- StavrosK 8y agoThank you, that looks very interesting. I'm not sure if it's cross-platform, but I'll play with it a bit and see.
- loeg 8y agoI wouldn't use enlightenment/EFL for a new project today. If you've got the opportunity to greenfield, Qt is a much nicer framework. EFL has a number of questionable design choices, covered a little bit here: https://what.thedailywtf.com/topic/15001/enlightened https://what.thedailywtf.com/topic/15001/enlightened .
- mcny 8y agoAnyone else getting Heroku application error? https://archive.fo/DdJpj https://archive.fo/DdJpj
- roblabla 8y agoI've always found Qt and Python (PyQt and PySide) to be a weird match. So many times did I end up with cryptic segfaults in the python VM due to some python object being collected "too early", creating a dangling pointer in the C++ world. This can happen if you forget to set the parent object, for instance. I know that those are things you have to worry about when you write C++, but when in the python world, you kind of expect everything to be refcounted for you. If I ever have to write a GUI app in python again, I'll probably chose another framework.
- Drdrdrq 8y agoThis just means that wrapper around C(++) code doesn't handle resources correctly. As you said, once inside Python you shouldn't care about object collection process. Nothing should lead to segfaults, in worst case you should get an exception about missing parent ref.
- nadioca 8y agomore exactly “underlying C/C++ object has been deleted" error.
- JasonFruit 8y agoIn my experience, those errors are easy to resolve: just assign the new object to something, so it isn't immediately deleted. A little awkward, maybe, and it shouldn't happen, but if that's the worst quirk of PyQT/PySide, I can deal.
- nadioca 8y agoThose errors are always related with a bad implementation where there is something holding a reference to the qt python object represented by the bidding therefore keeping it alive even when their c++ instance has been already deleted. The solution is to go back to the drawing board and improve the implementation :)
- icefo 8y agoThis is good ! I remember coding a GUI in PyQt5 when the first usables version of python 3 came out and it was incredibly painful. Almost no documentation was avaible and I was learning how GUI works. It took me a while to get a basic app running and from there I mostly translated the official docs to python.
- bitL 8y agoSadly, we still don't have the seamless UI building functionality Delphi had 15 years ago, allowing making a fairly advanced desktop app in a day. Jumping between Qt Designer and IDE back and forth is still an order of magnitude more complicated than it needs to be.
- jcelerier 8y ago> Jumping between Qt Designer and IDE back and forth is still an order of magnitude more complicated than it needs to be. ... uh ? the designer is part of the ide... nowadays you even have a code view synced with the UI editor in realtime (http://blog.qt.io/blog/2017/05/24/qt-quick-designer-qt-creator-4-3/ http://blog.qt.io/blog/2017/05/24/qt-quick-designer-qt-creat...)
- toopsss 8y agoIe you have to use qt designer as you ide or switch between IntelliJ/pycharm. It’s not ideal as IntelliJ is miles ahead of qt designer as a general purpose ide for python. I’m pretty spoiled at this point by the excellent refactorings and type support.
- WaltPurvis 8y agoHe was talking about writing Qt apps with Python. (This entire post is about writing Qt apps with Python.) Qt Creator is not a Python IDE.
- opencl 8y agoDelphi is still around, as is the open source clone Lazarus. It's certainly not as popular as it used to be but still actively developed with people using it.
- bitL 8y agoYes, though Pascal is now a fringe language. I was mostly ranting about best IDEs Python has such as PyCharm, where one has to go back and forth between Qt Designer, some command-line compilation stuff and PyCharm. It feels like some ancient way to waste time doing trivial stuff instead of getting app done quickly.
- ntoll 8y agoFWIW I use PyQt5 in a code editor project I maintain. While all GUI frameworks have hiccups and smells to various degrees, Qt and PyQt5 has been, relatively speaking, the strongest UI framework I've encountered for Python. Why? Ease of development, cross-platform reach, "batteries included" (e.g. accessibility features, important for my project), friendliness of the API and breadth of features immediately spring to mind. Perhaps PySide's return will encourage some competition in the Qt space for Python. For example, I wish it was simple to create a cross-platform installer for stand-alone Python apps that use Qt. Current solutions suffer from the 80/20 rule where the 20 usually contains something essential.
- mherrmann 8y agoSorry to be spamming here but check out my https://github.com/mherrmann/fbs https://github.com/mherrmann/fbs. It is literally the solution to your pain point.
- StavrosK 8y agoMan, when a project is this useful, spam away. Thanks for this.
- ntoll 8y agoAha... thanks for the heads-up. :-)
- fernly 8y agoNo, interesting and useful. But a few questions. So basically you have automated the job of calling PyInstaller to make a standalone app, plus the step of wrapping the app in an installer. Yes? In order to use this, if I read the tutorial[1] code correctly, I must modify my app to wrap everything -- or at any rate, all PyQt-related things? -- inside an AppContext, and modify the outermost level to create this. If so, this is easy enough for the tutorial but what if my app opens multiple windows and has code to create them spread over multiple modules (as one of mine does). Is there a simple way to get all these bits into one "context"? Or have I read too hastily? [1] https://github.com/mherrmann/fbs-tutorial https://github.com/mherrmann/fbs-tutorial
- 77pt77 8y agoArchived page because site is really slow: https://archive.is/y0YlA https://archive.is/y0YlA
- fladd 8y agoDoes anyone know of a Qt binding for Python that is actually pythonic (as in follows PEP 8)? Both PyQt and Pyside are just one-to-one wrappers that use C-style naming for everything. I find that really strange. The same holds for most other GUI libraries, like WxPython. It seems the only real pythonic GUI libraries are Tkinter and PyGobject.
- mherrmann 8y agoIt's so much better if it's one-to-one. You can use the same documentation. The same search terms. You don't have to translate back and forth in your head all the time. At the end of the day, PEP8 is just a convention and we're free to break with it where it makes sense. Imho, this is such a case.
- dragonwriter 8y ago> It's so much better if it's one-to-one. You can use the same documentation. The same search terms. You don't have to translate back and forth in your head all the time. Those are things that make it better for the library maintainers, sure, but presenting (and documenting) an API that is idiomatic, both in structure and behavior, for the host language is better for library consumers, as it doesn't force them to context switch between the idioms of the host language and the idioms of the foreign library.
- ktpsns 8y agoAgree with having a pythonic API. There are already examples in the "Hello Qt" which are easily solvable: app = QApplication([]) # should read instead: app = QApplication() where the empty list is the default argument. Also app.exec_() # should be instead app.exec() as it is also in the C++ API. These small things make the difference.
- mherrmann 8y agoexec is a reserved keyword in Python. The _ is there because the code wouldn't "compile" otherwise.
- dokka 8y agoI have been waiting for this my entire adult life. That's all I have to say about it.
- thomastjeffery 8y agoWhat about pygobject? What does Qt have to offer over GTK?
- dokka 8y agoI like pygobject too, but I've always wanted a QT library for python not written by a 3rd party. Most of the 3rd party libs will get you 90% there, but if QT commits to making the library, they won't leave me hanging. I've been wanting to build a python desktop app with the newest version of QT with lots of dynamic UI windows for a very long time, and this will allow me to do it.
- Sylos 8y agoHaven't used either, but people typically say that Qt's API is cleaner, that it's better suited for cross-platform applications (for example it has support for Android) and that it's more flexible (for example LXDE is being rewritten as LXQt, since the devs found GTK3 too heavyweight and too GNOME-centric).
- jcelerier 8y agohttps://doc.qt.io/qt-5.10/qtmodules.html https://doc.qt.io/qt-5.10/qtmodules.html
- adamnemecek 8y agoThis is like 10 years too late. This could have prevented electron.
- chimen 8y agoYou make it sound like that would have been a good thing. Why?
- _ZeD_ 8y agoElectron is bloated
- nadioca 8y agoMost interfaces created through web technology would be incredibly hard and slow to do using pyside/pyqt. We take for granted the non-blocking aspect of javasript where in python in order to make a slick interface would require to deal with threads/GIL in a much slower interpreted language compared with javascript running on V8. Qt (Qt Desktop) bindings for python are welcome. But, it's not a suitable for a viable replacement for electron. Maybe Qt Quick, but even qt quick has some decisions that can make incredibly uncomfortable to use in large applications.
- ptx 8y agoWe have asyncio now to handle things in a non-blocking way with async/await. Someone just needs to write an implementation of asyncio.AbstractEventLoop that hooks into the Qt event loop.
- always_good 8y agoAnd then they need to write an async version of everything you might want to use. And then they're done!
- ptx 8y agoNo, async versions of everything are already being written, based on asyncio. You just need the glue for using it with Qt.
- smnrchrds 8y agoIs is possible to use QML in a PyQt/PySide2 app? Using QML for interface and Python for logic would make perfect sense. But every PyQt article and tutorial I see is about QtWidgets.
- mottosso 8y agoYes, PyQt4/5 has supported this since it was first introduced, PySide2 just recently got some support for it although it is incomplete. Source: I maintain a Python/QML library https://github.com/pyblish/pyblish-qml https://github.com/pyblish/pyblish-qml
- pknopf 8y agoWe use PyOtherSide for exactly this. Works perfectly. I'm also working on a similar solution for .NET Core: https://github.com/pauldotknopf/net-core-qml https://github.com/pauldotknopf/net-core-qml
- StavrosK 8y agoDo you need PySide2 to support QML in order to use the Qt Designer?
- lbeltrame 8y agoI skimmed through the posts in the thread but no one seemed to mention the major pet peeve that (IMO) PyQt has, which is not the licensing, but the development model: 1. SIP files are generated and dropped into the tarball: no way to do that yourself (the tool is available, but completely undocumented). This is problematic when a new major Qt version is out, but PyQt hasn't updated yet (I had problems like this recently when building PyQt5 for Qt 5.11 for openSUSE) 2. There is absolutely no bug reporting: you have to join the mailing list, post about your issue, and hopefully get an answer or "fixed in next snapshot" (see below) 3. There's no source repository access, just frequently-released "snapshots". Backporting patches to stable releases (because perhaps fixes aren't in old versions) is a chore. 4. Submitting patches as well requires a ML post: not bad per se, but there's no real workflow for it (and hard to do anyway without having the current state of the code). I don't have to use PyQt professionally (all my stuff is parsing/querying/stats, so a GUI isn't necessary), but for my free time projects I preferred to learn C++ and Qt than go through PyQt again. And it's a shame since the bindings are quite good in quality.
- xioxox 8y agoThis isn't PyQt, but an update of PySide. However I find the PyQt developer very responsive to bug reports. It's a much better service vthan the usual post to a bug tracker and no response you get with many other projects.
- ChuckMcM 8y agoOh this is very convenient and cool. I'm go looking forward to developing gnuradio applications using this.
- pknerd 8y agoWill there be need of QT runtime for this?
- asafira 8y agoI'm sure others here have far, far more experience with QT that I do, I wanted to give my 2 cents: QT has been great for the experimental control software we run to perform experiments in our lab (https://github.com/LISE-B26/PyLabControl https://github.com/LISE-B26/PyLabControl --- note, the readme is unfortunately out of date, but it should be ready in a week or two). I tried a good number of other GUI libraries for python, but pyQT just worked far more quickly.
- Buetol 8y agoTook me a while to figure out the "pip install" command: pip install --index-url=http://download.qt.io/snapshots/ci/pyside/5.9/latest/ pyside2 --trusted-host download.qt.io (with python 3.6 or 2.5)
- RandomCSGeek 8y agoWhy though? Is there some useful benefit that python offers over C++, or is it just another language support so that people more comfortable with Python could use it? If I were ever to write a desktop app, which one should I choose, given I'm equally comfortable with both languages?
- gawkface 8y agoIt's like you say, and like the qt blog says, "opening to python world" About your second question (c++ vs python), even I am curious
- marcosdumay 8y agoPython is a much higher level language than C++, with all the problems and benefits of that.