PySide GUI Application Development
Format: PDF / Kindle (mobi) / ePub
Newbies to GUI programming in Python will find this book indispensable. As well as the basic concepts, you'll be taught PySide in detail through practical instructions and create your own applications with customized widgets and dialogs.
- Designed for beginners to help them get started with GUI application development
- Develop your own applications by creating customized widgets and dialogs
- Written in a simple and elegant structure to help you easily understand how to program various GUI components
Elegantly built GUI applications are always a massive hit among users. PySide is an open source software project that provides Python bindings for the Qt cross-platform UI framework. Combining the power of Qt and Python, PySide provides easy access to the Qt framework for Python developers and also acts as an excellent rapid application development platform available on all major operating systems.
This book aims to help you develop GUI applications easily using PySide. Python is easy to learn and use and its programs are relatively shorter than those written in other programming languages like C++ or Java. This book will introduce you to user interface programming in Python, allowing you to develop real-time applications in a shorter amount of time.
This book will take you through everything you need to know to develop UI applications. You will learn about installing/building PySide in various major operating systems as well as the basics of GUI programming. The book will then move on to discuss event management, signals and slots, and the widgets and dialogs available with PySide. Database interaction and manipulation is also covered.
In a nutshell, this book is great for learning how to program applications with GUI and for mastering how to develop your own applications and how to run them across platforms.
What you will learn from this book
- Download and install/build PySide, a cross-platform GUI development toolkit for Python
- Program GUI applications in an easy and efficient way
- Create and work with windowed applications
- Create menus, toolbars, status bars, and child windows
- Connect your GUI to a database and manage it
An accessible and practical guide to developing GUI’s for Python applications.
Who this book is written for
This book is written for Python programmers who want to learn about GUI programming. It is also suitable for those who are new to Python but are familiar with object-oriented programming.
items can be added. You don't have to set a layout for menu bar. Different platforms use different layouts for the menu bar. In Windows system, the menu bar is usually anchored at the top of a window under the title bar. In the Macintosh system, the menu bar is usually anchored at the top of the screen. Linux systems have both these display formats depending on the GUI style. QMenuBar automatically sets its own geometry to the top of the parent widget and changes it appropriately whenever the
row/column has a minimum width and a stretch factor. The widgets are added into the grid layout using the addWidget() function and the layout puts it into the correct cell. It is also possible for a widget to span across multiple rows/columns. The addItem() and addLayout() methods can also be used to insert widgets or other layouts into it. The grid layout also includes two margins as discussed in the box layout. An example program for the usage of grid layout is as follows. def SetLayout(self):
QSqlQuery.lastError(). [ 103 ] www.it-ebooks.info Handling Databases Inserting, updating, and deleting records In this section we shall look at the different ways we can perform the DML commands. A simple form of inserting the values in the table that we have created in our previous section is given as follows: myQuery = QSqlQuery() myQuery.exec_("""INSERT INTO employee (first_name, last_name, age, sex, income) VALUES ('Alice', 'M', 30, 'F', 5000.00) """) This would insert a single row in
the current record. The fields are numbered from left to right using the text of the SELECT statement. For example, in the following query, field 0 represents the first_name and field 1 represents the last_name: SELECT first_name. last_name FROM employee [ 105 ] www.it-ebooks.info Handling Databases Since QSqlQuery.value() takes an index positional argument, it is not advised to use SELECT * in the query; instead use the column names because we don't know the order of columns in the SELECT *
print(sys.exc_info()) In the preceding program, we have included a class to set the application icon and we call that function from our main program to set it. Remember to place the image in the same location as the program. On executing this program, we would get the output as shown in the following screenshot: As we have seen the basics of setting an application icon, we move on to explore more about the PySide.QtGui.QIcon class. This class provides a set of functions that provides