-2

I was looking into PyQt5 for one of my side-projects and would really like to get to learn it better. However, I wasn't sure how to correctly format the code. I've seen tutorials do class definitions for a main window and some do basic function definitions.

Which of these options tends to be favored and what does code tend to look like for that option? (i.e. for the class route are labels and other widgets added within a separate class or through a method within the main window class?, etc.)

I'm not necessarily asking for full code but just a basic structure to get started.

0

The strategy for organizing your classes heavily depends on the kind of GUI / Widgets are you going to use. Of course, your program inner logic should be separated from the GUI itself, and Qt provides useful patterns and tools to avoid fall in a terrible mess :-) I recommend you to read this StackOverflow post and check the official Qt python examples, which are not real tutorial but self-explanatory basic scripts where you can see some good practices and its basic structure:

/python/lib/site-packages/PyQt5/examples

Also, you will find tons of pre-5 python Qt examples in the web. Although PyQt4 and pyQt5 are not 100% compatible, adaptations are quite straighforward and do not affect the general structure of your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.