Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I am looking for a PyQt5 tutorial. It is rather complicated to start GUI development with Python for the first time without a tutorial.
I only found some PyQt4 tutorials so far, and since something changed from Qt4 to Qt5, for example the fact SIGNAL and SLOT are no more supported in Qt5, it would be nice to have specific tutorials for PyQt5.
Can someone please provide a tutorial on how to start GUI development with PyQt5?
As my travels into the depths of PyQt5 continue, so shall I continue to update this answer with some of the shinier treasures I find.
That being said, I am now taking a "rough draft" stab at a quick intro to PyQt5. I will also provide links to helpful resources. I am new to this framework as well, and I will elaborate on what I believe to be a good strategy for using it, as I figure that strategy out. There are likely other good strategies, so if anyone has anything to add, then please leave a comment. This is very much a work in progress.
Strategy
I've learned much from the example code as suggested in the other answer, but something the examples don't help with is PyQt5's deep magic. Frameworks with a lot of magic in them (PyQt5, Django, SQLAlchemy, ...) are great because an enormous amount of drudgery is abstracted away from you. On the flip side, it is not always clear what the hell is going on, or what you're supposed to do about it.
Luckily, it seems we have options:
QtDesigner: For those days when your keyboard catches fire, there's a rockin' GUI-Builder called in the installation package. When you see the code this produces (perhaps only in the community version?), you'll see why this may not be the panacea it seems.
QML: Another candidate for panacea: declarative GUI building from formatted JSON. Yum.
Qt Quick: The framework for QML. By this point, it may seem tantalizingly easy, but don't get sucked in by this stuff just yet. It always seems to come down to learning it by hand.
The Model-View Framework(1): Model-View (not MVC) separates the code that deals with presentation/interaction from the code that manages the data, with the aim of providing modularity.
Coding in PyQt5 is greatly simplified by using the set of classes that implement the Model-View design pattern. Model-View is an evolution of Model-View-Controller (MVC), in which the Controller has been reunited with the View. They seem like strange bedfellows, but, most of the program's logic is dealing with either the user, or data: it seems to make a certain sense, at least at a stratospheric level.
From a bird's eye:
Architecture(s)
Model-View-Controller
This widely-used design pattern separates the application into 3 layers:
Model ~> Encapsulates the data. Notifies View and Controller of any changes to the underlying data. This causes updates to the display of output or available commands, respectively.
View ~> Displays the relevant output from the Model to the user.
Controller ~> Encapsulates user interaction, and notifies the Model and View of relevant events.
Model-View
The Graphics View Framework(1) ~> Represent everything (including embedded QWidgets, etc) inside a QGraphicsScene as a QGraphicsItem (or derivative thereof), including proxy classes for embedding widgets. The items are supposedly highly optimized, and integrating OpenGL support is a one-liner, which is nice.
This design pattern puts the Controller inside the View. This way, the view is capable of handling the entirety of the user's interaction. In concrete terms, these are the Signals and Slots mechanisms.
User Interaction Management
Callbacks
Signals and Slots
..... ** I'm sorry, but I must sign off now. I'll be back to continue to add to this. **
Practical Example(s)
Like, for instance, you can take a tree view from the itemviews/editabletreemodel example, then swap in a file system model (QFileSystemModel) from the itemviews/dirview example and you've got a full (working) view of your directory tree. Pretty snazzy.
So, you would take the code from the editabletreemodel example:
headers = ("Title", "Description")
file = QFile(':/default.txt')
file.open(QIODevice.ReadOnly)
model = TreeModel(headers, file.readAll())
file.close()
self.view.setModel(model)
...and swap in the model from dirview:
model = QFileSystemModel()
model.setRootPath('')
self.view.setModel(model)
...and it just works. Amazing.
The next step (in my case) (*I think) is implementing a custom model which I will then use several views concurrently, but I don't know if that kinda thing fits your use case.
Resources
Here are some gems I found on my travels. Hopefully they help you on yours.
This is a tutorial on Model-View for Qt5.(1) It is a very detailed document from the official Qt5 docs. A good deal of useful documentation can be found at the Qt5 site. Keep in mind, it's for Qt5 (the C++ library), but the difference is trivial to read through (and the PyQt5 official docs point there anyway).
This PDF contains a quick high-level to PyQt4's Model-View framework. Note that is it for PyQt4 (not PyQt5), but it is actually for Python (as opposed to C++), and I found it very quickly taught me a lot.
I am just starting to play with the Graphics View, and am finding this tutorial on the Graphics View Framework very helpful. This is the same View that is used in the qtdemo example code to generate some slick effects. I'll be updating this in a bit.
This is a complete list of all of the Qt5 Modules.
This is a complete list of all of the Qt5 Classes.
This is a complete list of all functions in the Qt5 API.
As katsh pointed out in another answer's comments, here is a link to the example code for PyQt5.2.1 on GitHub
Additionally, a copy of the example code comes packaged with your distribution and can be found at:
%PYTHON_HOME%\Lib\site-packages\PyQt5\examples
If you're using PyDev (Eclipse), you can run examples by simply right-clicking an example's main module file in PyDev Package Explorer or Navigator =:> Run As =:> Python Run
The best one, in my (not so) humble opinion, is:
%PYTHON_HOME%\Lib\site-packages\PyQt5\examples\qtdemo\qtdemo.py
Among my current projects, I'm in the process of reverse engineering this example. If you check it out, you'll see why. To be continued.. ;)
Enjoy!
Been looking for PyQt5 tutorials for some time? Look no further! You won't find many around the internet.
Not really tutorials, but pretty self-explanatory basic scripts under the following path:
/python/lib/site-packages/PyQt5/examples
you will find about 100 examples in 30 folders ranging from beginner to advanced, covering basic windows, menus, tabs, layouts, network, OpenGL, etc.
Have a look at http://www.thehackeruniversity.com/2014/01/23/pyqt5-beginner-tutorial/ This is a newbie friendly tutorial
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I know this question has been asked before but those questions typically lack specific details and result in answers that say something like "It depends what you are trying to do..." so the main gist of this app is that it retrieves remote data (ex. text) and object (ex. images).
Since PHP and python are the two programming languages I feel comfortable with I felt python was more suited for desktop gui apps. I'm creating a desktop music player and here are some of the technical specs I want to include:
A sign in construct that authenticates user credentials (Like
spotify, skype, league of legends) against a remote database (This
will be in mysql.) My thinking is to create a web api for the client to query via HTTP/HTTPS GET/POST
A client side SQLite database that stores the filename, filepath and
id3 tags of the song so upon launching, the application displays each song in a row with the song length, artist, album, genre (Like iTunes)
Retrieve remote images and display them within the application's frame (Like skype displays a person's profile picture.)
Must be cross-platform (At least in Windows and Mac), look native in different OS's but the native look and feel should be easily overridden with custom styles (Ex. rounded buttons with gradients.)
Compilation for Windows and Mac should be relatively straightforward
Of the popular python gui toolkits like PyQt, PyGTK, Tkinter, wxPython, Pyjamas, PyGObject and PySide which are well suited for my application and why? Why are the others not well suited for these specs? Which have good documentation and active communities?
Welcome to a fun area:
Watch out for urllib2: it doesn't check the certificate or the certificate chain. Use requests instead or use ssl library and check it yourself. See Urllib and validation of server certificate Sometimes a little ZeroMQ (0mq) can simplify your server.
You should consider shipping a self signed certificate with your application if you are a private server/private client pair. At that point, validating the certificate eliminates a host of other possible problems.
While you could read a lot about security issues, like Crypto 101, the short version is use TLS (the new name for SSL) to transmit the data and GPG to store the data. TLS keeps others from seeing and altering the data when moving it. GPG keeps others from seeing and altering the data when storing or retreiving it. See also: How to safely keep a decrypted temporary data? Enough about security!
SqlLite3, used with gpg, is fine until you get too large. After that, you can move to MariaDB (the supported version of MySQL), PostGreSQL, or something like Mongo. I'm a proponent of doing things that don't scale and getting something working now is worthwhile.
For the GUI, you'll hate my answer: HTML/CSS/JavaScript. The odds that you will need a portal or mobile app or remote access or whatever are compelling. Use jQuery (or one of its lightweight cousins like Zepto). Then run your application as a full screen application without a browser bar or access to other sites. You can use libraries to emulate the native look and feel, but customers almost always go "oh, I know how to use that" and stop asking.
Still hate the GUI answer? While you could use Tcl/Tk or Wx but you will forever be fighting platform bugs. For example, OS/X (Mac) users need to install ActiveState's Tcl/Tk instead of the default one. You will end up with a heavy solution for the images (PIL or ImageMagick) instead of just the HTML image tag. There is a huge list of other GUIs to play with, including some using the new 'yield from' construct. Still, you do better with HTML/CSS/JavaScript for now. Watch the "JavaScript: the Good Parts" and then adopt an attitude of ship it as it works.
Push hard to use either Python 2,7 or Python 3.3+. You don't want to be fighting the rising tide of better support when you making a complicated application.
I do this stuff for FUN!
GUI library
First of all, please leverage the work people have done to compile this GuiProgramming list.
One one the packages that stood out to me was Kivy. You should definitely check it out (at least the videos / intro). The Kivy project has some nice
introduction. I have to say I haven't followed it in full but it looks very promising. As for your requirements to be cross-platforms you can do that.
Packaging
There is an extensive documentation on how to package your app for the different platforms. For MacOSX and Windows it uses PyInstaller, but there are instructions for Android and iOS.
Client-side database
Yes, sqlite3 is the way to go. You can use sqlite3 with Kivy. You can also use SQLAlchemy if you need to connect to your sqlite database or if you need to connect to a remote one.
Retrieving content
The requests library is awesome to do http requests and IMHO is much simpler to use than a combination of httplib, urllib2.
Both PySide and WxPython support all five of your requirements. WxPython uses actual native widgets and also has custom extensions and widgets built on top. It has goodies like wx.CallAfter which'll allow you to run your background tasks in a separate thread and hop back on the UI thread easily.
PySide has a nicer API but draws its own widgets that imitate the underlying OS's UI. It's not as mature as WxPython and packaging it with tools like cx_freeze and PyInstaller is slightly more involved.
Also I recommend that you use an ORM like peewee over plain Sqlite3 for the data storage, it makes managing the data a lot easier and plays well with the freezing tools.
Of course the answer always remains; it depends on your needs and wants, but putting that aside I would say; go with Qt/QML. Qt with QML has been gaining a lot of traction lately, and with PyQt5 just release, it definitely seems like a good and future-proof option. It is cross platform, easy to work with and supports theming.
I highly recommend you watch this video in which they seem to do exactly what you want. In less than an hour they build a simple application that retrieves data (including images) from an outside source and list them on screen. It is also easy to make responsive applications (scaling easily to different screen sizes).
Lastly, I don't know what your license requirements are. PyQt is licensed either under the GPL, or under a commercial license. So if your application is open source, PyQt is perfectly fine. If your application will be proprietary you'dd be better off using PySide, which is LGPL.
Good luck!
I only got expirience with Qt-based Python GUI-toolkits, and found them to be very powerful, well documented and simple to use (as long as you stay away from model-view framework). And they can do all the things you mentioned. So my recomendation would be PyQt or PySide. PySide's advantage is it's license - LGPL, so if your stuff is proprietary - go for PySide. PySide has some troubles however, as it is basically abandoned as of writing this, so you will have to dodge some bugs (nothing realy critical IMO). PyQt is more actively maintained and developed, but it's GPL or commercial (about 400 euros). So if your stuff is free, you should choose PyQt. And yes, use ORM, if possible. Just my 2 cents.
Actually working on a project in python with PyQT, we choose to create widgets that were "unpleasant" or that didn't have a good enough behaviour.
So, we finally found that QToolbox, QDate and some others had a behaviour non acceptable for the project, so we had to adapt these.
We had also to create a complete new widget : A scheduler.
As we were creating these, it has been decided that it took too much time. So we were asked to think about other libraries.
I actually found a project of a scheduler in wxPython, that actually looks like what we want ( but we believe that we'll have to adapt it a lot ). Here it is : http://code.google.com/p/wxscheduler/
So, I ask everyone that have some more experience than me in GUI programming in python : Do we need to start again the project in anything other than PyQT? I know the question is weird, but what you need to know is :
The project has now been going on for 2 months
I know only PyQT, and started working in python 2 month ago
We are currently 3 in the project, and we currently know only PyQT
We have currently managed a lot of the PyQT widgets, and were starting to code these new widgets.
Please help us =)
Thanks
Edit : I should have add that the project is opensource and multi-platform
Feel free to look at other libraries if you like. Robin Dunn, the creator of wxPython, recently started working on PySide and he found it somewhat similar to wx, so you might find that wxPython will fit your brain fairly well too. I certainly think wx's class names are more intuitive than PyQt's. The only way to know for certain is to actually experiment a little and see if it works. I will say that the wxPython community is one of the best Python communities I've dealt with over the years.
One possibility would be to use an HTML scheduler control via QtWebKit. If your UI can accommodate a QWebView in the place where you'd otherwise have a custom scheduler widget, there are probably a number of excellent scheduler widgets (implemented as jQuery plugins, etc.) you could choose from.
we choose to create widgets that were "unpleasant" or that didn't have
a good enough behaviour.
Why don't you create "pleasant" widgets ?
so we had to adapt these.
Yes. It is the solution.
it has been decided that it took too much time
Don't you think it would take much more time if you change the whole GUI API ?
As for i know, there is not such native Scheduler in any Python GUI library, especially one you could use with Qt. I don't think it would be so long to recreate one, unless you have very specific needs, that would confirm you wouldn't find a such existing thing in an existing library.
Concerning wxScheduler, i guess you can have a look to the code, even it uses wxWidget and you're working with Qt, to get an idea how to do it.
How do I begin learning Twisted? What books, documentation or tutorial do you guys recommend?
The reason I asked this question is that I think learning Twisted would help me otherwise also in learning concepts related to network programming (terminologies and how it works and stuff) I have heard that the documentation for Twisted is not that good. Is is true?
Note that I am looking for some advise that actually helped you. I am looking for your experience. PS: I am aware of the official documentation. There is also the O'Reilly Book on Twisted; is that good?
I'm finding this tutorial, linked to from the third party documentation section of the main twisted documentation page, to be well-written and instructive.
The tutorial consists of numerous iterations of the implementation of a "Poetry Server and Client". It starts with a blocking, non-Twisted version, and works up to a full Twisted version. Each step introduces new abstractions and presents problems which are resolved in the succeeding steps.
The code which implements each step is made available as a git repo.
The way i learned twisted was by starting a small project and lots of googling around; the twisted tutorials are sometimes not very clear, its just getting used to the framework and the way it works...
EDIT:
itd also recommend trying to understand what twisted is based on, the whole idea of twisted is to provide event driven programming for python, along with some other features such as asynchronous sockets and web server classes.
A quick explanation of deferreds and callbacks, which is the whole idea behind twisted, is creating an event (deferred object), then attaching a callback to it; then at some point ur going to fire the event, and the callback is triggered with a result (it could be null) from ur event operation. A good example is, if you have a button on a form, you create an event (a deferred object) then u attach a callback, when the user clicks a button, they fire the event, and the callback function is called to handle that event.
i hope this will give u a good general idea of what twisted is and how it can be used in a python environment, there is also IronPython (.NET) which has eventing as well.
~george
Look at the samples that come with twisted's documentation. Also, the documentation is not bad, but it is not very complete. Also, the API docs are quite good in fact.
When you know with which part you start, just try and play with the code until you're stuck, then google samples relating to your code and ask on stackoverflow.
As mentioned before the Krondo Twisted Introduction is pretty nice. But the Twisted book by o'reilly isn't bad either.
I've only got the first edition (from 2005) of the book and I think it is better structured than the Krondo tutorial.
It includes standard tasks (like downloading a web page) and gives two sections to every task.
"How do I do that" and afterwards "How does it work".
I think the book is pretty good if you don't have the time (or don't want to take it) to read through the Krondo tutorial.
One thing I miss in the o'rilley book though is inline callbacks. Maybe they've added some chapter about it in new editions, since inline callbacks were added later to twisted.
Especially if you are not a fan of reading from a screen I would suggest getting the book.
(Also it includes an interresting foreword from the twisted inventor)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I'm downloading Python 3.1.1 and that comes with the IDLE correct?
I'm also downloading QT for Windows which I'm told is a good GUI framework to work with Python.
What projects should I try to make in order to grasp some of the goodies Python brings to the table?
Thanks a bunch SO.
I highly recommend
http://www.diveintopython3.net
It assumes you already understand programming, and walks you through examples that demonstrate the unique abilities of Python.
Do the next project you intended to program with your prefered language with Python.
If you are new to python, why not start with some simpler command line projects? I know you said you are not new to development, but maybe you should spend some time with the core python stuff before tacking on a GUI framework. Just a suggestion.
Also, I would point out that Python 3+ code looks a bit different than a lot of the python 2.x code samples you will see around the internet. I have found Python 3 to be not the best in terms of backward compatibility. You might want to start out with a 2.x version of Python to get the most out of the plethora of Python tutorials on the internet, then move to Python 3 if you need it.
Write a simple Text Editor.
That was one of the projects i started when i first learned python. It gets you used to the GUI framework, file IO, many types, OOP, lots... It's something that you can grow over time as your confidence builds and it's cross platform so it's handy.
If python is your first dynamic lanugage you might want to play with some of it's dynamic aspects.
For example, using the getattr and setattr methods on objects, you could write a class that provides a fluent way of accessing elements from an XML document. Rather calling methods on an object with parameters like 'xml.getnode("a").getnode("b")' you could dynamically lookup the nodes as attributes and allow 'xml.a.b' instead. I thought this was very cool having come from static languages.
Note that this won't neccessarily give you a great feel for python in general (although you'll pick up the language as you go) but it will give you a taste of what is possible in dynamic languages.
PythonChallenge
Code Golf
Google Code Jam
These are good ways to practice learning Python.
Might I also suggest that you consider using a different IDE.
If you are interested in GUI programming, I would suggest looking into wxPython, PyWin32, easyGUI, TkInter (which is bundled with the Python distribution)
Python Challenge This is fun and interesting to learn Python programming.
While it is a matter of personal preference, I certainly wouldn't want to play around with a GUI framework when starting out -- I would want to get a feel for the language first by playing around with smaller snippets, such as those suggested on Code Golf. While getting your code to fit into the smallest number of bytes perhaps isn't the best way to learn good design, I think it's a good way to learn parts of the language. Certainly, just doing the tasks without necessarily trying to compact them down excessively could be helpful.
A project I wish someone would write: a friendly GUI that wraps around the scanner library and the PDF library, and lets the user easily scan and file documents.
It would have a toolbar with big buttons: "scan letter", "scan brochure", "scan photo". These would respectively choose high-resolution black-and-white, medium-resolution color, and high-resolution color.
The user would plop down the document and hit one of those buttons. Python would wake up the scanner and have it scan, and then would use Python Image Library or something to auto-detect the size of the actual scanned document and auto-crop down to minimal size.
For "scan photo" you would get a JPEG. For the others, you would get a PDF. And it would have an option where you could scan several pages and then select the scanned pages, and say "group" and it would make a single PDF out of them.
Other useful toolbar buttons would be: "Copy Letter", "Copy Brochure", "Copy Photo". These would scan and then immediately print on an appropriate output device (or just on the default output device for your first version).
If you want to go crazy, you could add an OCR function to try to recover searchable text from the scanned images, and put that in the PDF as tags or something.
Someday I will write this if nobody else does...
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed last year.
Improve this question
I'm developing a graphical application to present data (not a game but a real workhorse app). It needs to be cross platform, so I have chosen:
python
openGL (I need 3D, blending, textures etc)
pyopengl
wx/pywx - windowing, dialogs etc.
The last component - WX - raises the question. I can put together a very nice looking app (the prototypes look slick) - but when I need to interact with the user to ask questions, get input, I have to use WX. It makes the app look inconsistent to have traditional UI with traditional dialogs and combos and text entry on top of a full screen 3D app with blending, smooth motion, textures etc.
Has anyone developed a GUI using OpenGL and python? Can you share with me the toolkits and/or tricks you used? I need combos, text entry, buttons, radios, option buttons, tree view.
There are some toolkits out there, but they are either incomplete or old and unmaintained. A great example is pyUI (http://pyui.sourceforge.net/) - looks slick but untouched for years.
This is not an answer, more of a plea: Please don't do that.
Your reimplemented widgets will lack all sorts of functionality that users will miss. Will your text-entry boxes support drag'n'drop? Copy/paste? Right-to-left scripts? Drag-select? Double-click-select? Will all these mechanisms follow the native conventions of each platform you support?
With Wx your widgets might look inconsistant with the app, but at least they'll look consistant with the OS which is just as important. And more importantly, they'll do what users expect.
(edit) Three posts, and -3 points? Screw this den of karma-whores. Original poster: I have implemented a basic set of widgets in OpenGL (for a game UI) and it was an endless nightmare of a job.
In the latest releases of QT you can draw widgets into your OpenGL context, if you really would like to do something like that. Otherwise there is CEGui that is used in some game engines.
Implementing GUI Widgets yourself unless you want to edify yourself is a waste of your time, unless you would be satisfied with the most rudimentary of looks and functionality.
Python + Qt + OpenGL -
I surely believe any application can be written faster and better using python.
QT4 is cross-platform, beautifull, implements everything you need from widgets (acessibility, etc...), and...it integrates with OpenGL. That means, you can simply have a widget that is a viewport to openGL stuff you render in your code.
Another 3D capable solution that would cover most things, but not so nioce on user interface is to extend Blender3D with a python script. It has the 3d capabilities and rendering , you script it in python all of the same, and it would be cross platform - and you get higher level tools for woriking with the 3D things than openGL alone.
There are obvious drawbacks, mainly from the UI standpoint when compared with PyQT but it could be done.
You might want to look at Clutter, it looks pretty cool. I haven't used it yet but I intend to in an upcoming personal project.
Try Qt instead of wx.
QT is cross platform, and you can style things alot using CSS. It's extremely well documented and has excellent python bindings. In point of fact, I use the C++ documentation and not the PyQT documentation.
Both wx and QT do an excellent job of creating an application that matches the OS look and feel.
It is also possible to implment all the widgets yourself directly in openg, this slashdot post lists some of the sets available
http://ask.slashdot.org/askslashdot/02/12/24/1813219.shtml?tid=156
fox is probably the most developed but looks like windows on all platforms.
Blender is the only app I know of with a GUI written fully in OpenGL...
the only problem is it's in C++.
I'm a Python developer as well, but I'm just getting into using OGL
I honestly don't think there are any toolkits to develop a GUI in OGL...
the Blender developers are giving me runaround documentation instead of direct help...
but I'll let you know what I figure out ;)
EDIT:
here's a bit of documentation on PyOpenGL's functions:
http://pyopengl.sourceforge.net/documentation/manual/reference-GLUT.html
"cegui" is a good choise there is also a gui editor called "ceed" to generate the layout xml files. cegui also has python bindings and its well documented and used in many game engines
my friend.
I believe I have found your answer ;)
http://glinter.sourceforge.net/
I havn't yet tried it, but it seems quite promising.
(I'll edit this if it doesn't work)
EDIT:
eh...
it uses Tk, PMW, and WX...
(not quite what I want)
you can give the CVS download a try...
(there's no released packages, but the CVS runs)