Every application needs one - and only one - QApplication object to function. The core of every Qt Applications is the QApplication class. If you're already familiar with event loops you can safely skip to the next section. What's the event loop?īefore getting the window on the screen, there are a few key concepts to introduce about how applications are organized in the Qt world. This was a legacy feature avoid a clash with the exec reserved word in Python 2. Application will (by default) exit when last window is closedįinally, we call app.exec() to start up the event loop. Every application needs at least one (.but can have more) Holds the user-interface of your application show() and run the app, but you'll have no way to quit it! So, after creating the window object, we must always call. Widgets without a parent are invisible by default. This means you can technically create a window using any widget you like. In Qt all top level widgets are windows - that is, they don't have a parent and are not nested within another widget or layout. If you do mess up, Python will let you know what's wrong. Type it in verbatim, and be careful not to make mistakes. The source code for the application is shown below. ![]() We'll be editing within this file as we go along, and you may want to come back to earlier versions of your code, so remember to keep regular backups. app.py) and save it somewhere accessible. Let's create our first application! To start create a new Python file - you can call it whatever you like (e.g. These will be explored in more detail in the subsequent tutorials. Finally we'll look at Qt's QMainWindow which offers some useful common interface elements such as toolbars and menus. Then we'll take a brief look at the event loop and how it relates to GUI programming in Python. ![]() In this tutorial we'll learn how to use PyQt to create desktop applications with Python.įirst we'll create a series of simple windows on your desktop to ensure that PyQt is working and introduce some of the basic concepts.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |