Live data from Hacker News

PyQt5 Tutorial: Create a Python GUI in 2018

build-system.fman.io

111–120 of 211 posts

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#111
post #75

I gave up on QT and decided instead to invest time learning javascript frameworks, which provide a lot more flexibility for creating apps.

Then try QML! You can create Qt apps using JavaScript (it's ES5 though).

QML is actually pretty awesome, I got into it through KDE/Plasma widget development. I think it should be possible to get newest JS working using Babel in your build pipeline. I think it makes a LOT of sense in cases where you develop a UI and can't effort to embed webkit/chrome.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#112
post #90

Earlier quoted context omitted.

You can do all those (sorting, filtering, etc) in Qt as well using the Model/View components. There is a bit of a learning curve to understand the "Qt way of doing MVC", but after that it works fine. At work we use Qt5 with both C++ and Python (through PyQt) and I love it.

Thanks! What I'd like to know more specifically is if there are some ready-made components already packing a lot of these functionalities without needing too much custom logic, or you need to roll out your own from low-level ones?

QTableView supports pretty much everything. Model proxies like QSortFilterProxyModel give sorting and filtering on models not supporting it natively (at a performance cost, i.e. keeping sorting columns in memory).

The model/view components scale to ~infty items, if the model is correctly implemented. They also support lazy loading.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#113
post #74

Earlier quoted context omitted.

What's the memory consumption of pyQT compared to electron apps?

An order of magnitude lower. I see 40Mb on macos right now for a simple app.

I see a simple electron app using 140MB total. Measured by running 'free -m' before and after starting the app and waiting a while for a gc to run.

Measuring memory use is difficult.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#114
post #97

Still using tkinter here which is python's default GUI, what's the license for PyQt5? For me learning Qt in general is another big investment of limited time, so far I have been using tkinter with python and it works well.

PyQt5 is dual licensed GPL / commercial. I.e. free if your work is GPL, pay if your work is proprietary.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#115

This is a case where the "in 2018" in the title is very helpful, as Googling information about Python and Qt usually returns something dreadfully out of date. (and as other comments note, there are lots of new companion tools/competitors like Electron)

The API still looks messy and unpythonic though, sadly. Look at the basic hello world example. Why do I need to pass QApplication an empty array? Why am I calling a method ending with _ to launch the program? And the fact the label magically attaches to the app through some side effect is also confusing. Does anyone know if there's any good shim/wrapper around PyQt that has a better API?

The confusion will go away if you learn how things work under the hood(you should know what an event loop is, learn about Qt widgets parenting, signals and slots, layouts),also in practice you use the GUI tools to create and modify GUIs though you need to learn how to use them properly and not create absolute positioned layouts.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#116
post #51

I'm using PyQt for a project right now, and overall it's a nice feeling as always. The model/view classes are great, once you get the hang of them. There are a lot of utilities for things like persistence and threading (but I wouldn't cross the streams with python threads), and it's all crossplatform and very mature by now, the only issues are usually around packaging. QML is also very powerful, but I'm usually happy…

> (but I wouldn't cross the streams with python threads)

You can't. Also keep in mind that Python's thread-local storage only works with the threading module threads, not Python threads created elsewhere (e.g. by the "outer" C++ application itself or by a QThread wrapper). It's really quite poorly implemented there IMHO.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#117
post #4

I like the tutorial, but I don't know why you would use PyQt these days. Tkinter is more permissive and has wrappers like appJar which make it disgustingly easy to put together a quick, ugly GUI. If you're building a desktop app that needs to really look good and be fast, why are you using Python?

> If you're building a desktop app that needs to really look good and be fast, why are you using Python? Why not? For an app to feel fast, you need to make it responsive and non-blocking. You can easily make apps with Python and Qt or Gtk that start instantly and never seem to hang. Discipline when it comes to not running things on the main thread, using proper async techniques etc. is more important than the number…

> more important than the number crunching ability of your programming language

I work on a data visualization program written with PyQt. As an example, in a scatterplot with several hundred thousand rows, the bottleneck is not number crunching. Numpy could go up another order of magnitude. Probably two. The bottleneck is figuring out efficient ways to display all of the points, correctly, and make them pickable.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#118

In commercial settings, I wonder how hard it really is to package this up? I've been building/distributing fully cython'd installers for a while (to sort-of hide the source as well as make a convenient package)... I wonder if that would be harder with PyQt for some reason? "In the Python world, the process of turning source code into a self-contained executable is called freezing. Although there are many libraries th…

http://nuitka.net/ is what you are looking for.

It's robust, proven, does work well with C extensions (including numpy and QT) and produces stand alone binaries. You can produce binaries for Windows, Linux and Mac (but not cross compile). It works by turning the whole Python code into C before compiling the result. The additional benefit of that is that you gain a bit of execution speed.

The project is amazingly little known in the community while PyInstaller, py2exe, cx_Freeze, bbfreze, py2app are: nuikta works better, handle more edge cases, target more OSes and support recent versions of Python.

The best way to be convinced is to read the last entry of the blog on the home page: the guy is meticulous with this project.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#120
post #113
post #74

Earlier quoted context omitted.

An order of magnitude lower. I see 40Mb on macos right now for a simple app.

I see a simple electron app using 140MB total. Measured by running 'free -m' before and after starting the app and waiting a while for a gc to run. Measuring memory use is difficult.

FYI, you can open dev tools in electron and manually trigger GC [0].

[0] https://i.imgur.com/JbWArmR.png

Post reply on HN