Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Pyside GUI Application Development- Second Edition
Pyside GUI Application Development- Second Edition

Pyside GUI Application Development- Second Edition: Develop more dynamic and robust GUI applications using PySide, an open source cross-platform UI framework , Second Edition

Arrow left icon
Profile Icon Loganathan Profile Icon Jaganmohan
Arrow right icon
€13.98 €19.99
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.7 (3 Ratings)
eBook Jan 2016 144 pages 2nd Edition
eBook
€13.98 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Loganathan Profile Icon Jaganmohan
Arrow right icon
€13.98 €19.99
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.7 (3 Ratings)
eBook Jan 2016 144 pages 2nd Edition
eBook
€13.98 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€13.98 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Pyside GUI Application Development- Second Edition

Chapter 2. Entering through Windows

The main part of any GUI program is to create windows and define functionalities around it. We will start exploring the ways to create windows and customize it in this chapter, and we will move on to create a real-life windows application in the next chapter.

The widget is the center of the user interface. It receives the user inputs from the mouse, keyboard, and other events of the window system, and paints a representation of itself on the screen. Every widget is rectangular, and sorted in a Z-order. Z-order is an ordering of displayed overlapping windows. The window with a higher Z-order will appear on top of windows with lower Z-orders. A widget is clipped by its parent and by the widgets in front of it. A widget that does not have a parent is called a window and is always independent. Usually, windows have a frame and a title bar at the least, but it is possible to create them without these by setting some windows flags. This chapter explains...

Creating a simple window

The QWidget is the base class for all the user interface classes. A widget can be a top-level widget or a child widget contained in a top-level or parent widget. Now, let's create a top-level window using QWidget. The constructor of the QWidget class takes two optional parameters, parent and flags. The parent parameter can be a QWidget object and the flags parameter can be a combination of PySide.QtCore.Qt.WindowFlags, as follows:

# Import required modules
import sys, time
from PySide.QtGui import *
from PySide.QtCore import *

# Our main window class
class SampleWindow(QWidget):
    # Constructor function
    def __init__(self):
        super(SampleWindow,self).__init__()

        self.initGUI()


    def initGUI(self):
        self.setWindowTitle("Sample Window")
        self.setGeometry(300, 300, 200, 150)
        self.setMinimumHeight(100)
        self.setMinimumWidth(250)
        self.setMaximumHeight(200)
        self.setMaximumWidth(800)
 ...

Creating the application icon

We created our sample window, and now we go on to customize it with some features fitting our needs. For each customization, we add a new function under the SampleWindow class in the previous program to define its properties, and we call this our main function to apply these properties on the sample window. In this section, we define an icon to be set on the window that we created. An icon is a small image that is created to visually emphasize the purpose of the program. It is displayed in the top-left corner of the application window. The same is also displayed in the taskbar when the application is minimized. As a prerequisite for this program, you may need an icon image with dimensions similar to the image that is used here (72 X 72). You can create your own image or download it from the book's website if you wish to use the one used in this program:

# Import required modules
import sys, time
from PySide.QtGui import QApplication, QWidget, QIcon


#...

Showing a tooltip

Our next customization is to show a tooltip for the different modes of icons that are shown. Tooltip is handy when you need to display some help text or information to the users. Displaying help text for the widgets that are used in the window is an integral part for any GUI application. We use the PySide.QtGui.QToolTip class to provide tooltips (also called balloon help) for any widget. The QToolTip class defines the properties of the tooltip, such as font, color, rich text display, and so on. As an example, the font properties can be set as follows:

QToolTip.setFont(QFont("Decorative", 8, QFont.Bold))

After setting the font, we set the tooltip to the widget by calling the setToolTip() function provided by the QWidget class:

   myLabel1.setToolTip('Active Icon')

The QFont class specifies a font that has to be used to draw the text. Using the functions that are provided by this class, we can specify various attributes that we want our font to have. If the...

Adding a button

The next customization is to add a button to our application. The most common button that is used in any GUI is a push or command button. We push (click on) the button to command the computer to perform some action or answer a decision. Typical push buttons include: OK, Apply, Cancel, Close, Yes, No, and Help. Usually the push button is rectangular with some label on it. It can also have an optional icon associated with it. It is also possible to define a shortcut key combination to the button to which it responds on clicking the key combination.

The button emits a signal when it is activated by any external event, such as a mouse click or by pressing the spacebar, or by a keyboard shortcut. A widget may be associated with this key click event, which is executed on receiving this signal, and it is usually called a slot in Qt. We will learn more about signals and slots in the later chapters. As for now, be informed that a signal will connect to a slot on emission. There can...

Centering the window on the screen

The windowed applications based on type and functionality get displayed in the center for main applications, top right for notifications, and as an icon in the status bar of the screen. It is best practice for any main GUI application to display the window centered on the screen. There are two advantages of doing this. The first is to get the attention of the user, and the other is to adjust to different display formats of the various monitor screens.

There is no straightforward method to center the window by calling a predefined function of some class. Therefore, we write our own method, called center, to position the window central to any screen. This method takes the object that it is calling and centers it with respect to the screen that it is displayed on:

    def center(self):
        """ Function to center the application
        """
        qRect = self.frameGeometry()
        centerPoint = QDesktopWidget().availableGeometry...

Creating a simple window


The QWidget is the base class for all the user interface classes. A widget can be a top-level widget or a child widget contained in a top-level or parent widget. Now, let's create a top-level window using QWidget. The constructor of the QWidget class takes two optional parameters, parent and flags. The parent parameter can be a QWidget object and the flags parameter can be a combination of PySide.QtCore.Qt.WindowFlags, as follows:

# Import required modules
import sys, time
from PySide.QtGui import *
from PySide.QtCore import *

# Our main window class
class SampleWindow(QWidget):
    # Constructor function
    def __init__(self):
        super(SampleWindow,self).__init__()

        self.initGUI()


    def initGUI(self):
        self.setWindowTitle("Sample Window")
        self.setGeometry(300, 300, 200, 150)
        self.setMinimumHeight(100)
        self.setMinimumWidth(250)
        self.setMaximumHeight(200)
        self.setMaximumWidth(800)
        self.show(...

Creating the application icon


We created our sample window, and now we go on to customize it with some features fitting our needs. For each customization, we add a new function under the SampleWindow class in the previous program to define its properties, and we call this our main function to apply these properties on the sample window. In this section, we define an icon to be set on the window that we created. An icon is a small image that is created to visually emphasize the purpose of the program. It is displayed in the top-left corner of the application window. The same is also displayed in the taskbar when the application is minimized. As a prerequisite for this program, you may need an icon image with dimensions similar to the image that is used here (72 X 72). You can create your own image or download it from the book's website if you wish to use the one used in this program:

# Import required modules
import sys, time
from PySide.QtGui import QApplication, QWidget, QIcon


# Our main...

Showing a tooltip


Our next customization is to show a tooltip for the different modes of icons that are shown. Tooltip is handy when you need to display some help text or information to the users. Displaying help text for the widgets that are used in the window is an integral part for any GUI application. We use the PySide.QtGui.QToolTip class to provide tooltips (also called balloon help) for any widget. The QToolTip class defines the properties of the tooltip, such as font, color, rich text display, and so on. As an example, the font properties can be set as follows:

QToolTip.setFont(QFont("Decorative", 8, QFont.Bold))

After setting the font, we set the tooltip to the widget by calling the setToolTip() function provided by the QWidget class:

   myLabel1.setToolTip('Active Icon')

The QFont class specifies a font that has to be used to draw the text. Using the functions that are provided by this class, we can specify various attributes that we want our font to have. If the font type that we...

Adding a button


The next customization is to add a button to our application. The most common button that is used in any GUI is a push or command button. We push (click on) the button to command the computer to perform some action or answer a decision. Typical push buttons include: OK, Apply, Cancel, Close, Yes, No, and Help. Usually the push button is rectangular with some label on it. It can also have an optional icon associated with it. It is also possible to define a shortcut key combination to the button to which it responds on clicking the key combination.

The button emits a signal when it is activated by any external event, such as a mouse click or by pressing the spacebar, or by a keyboard shortcut. A widget may be associated with this key click event, which is executed on receiving this signal, and it is usually called a slot in Qt. We will learn more about signals and slots in the later chapters. As for now, be informed that a signal will connect to a slot on emission. There can...

Left arrow icon Right arrow icon

Key benefits

  • Designed for beginners to help you get started with GUI application development
  • Develop your own applications by creating customized widgets and dialogs
  • Written in a simple and elegant structure so you easily understand how to program various GUI components

Description

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. This book will take you through everything you need to know to develop UI applications. You will learn about installing and 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. By the end of this book, you will be able to program GUI applications efficiently and master how to develop your own applications and how to run them across platforms.

Who is this book 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.

What you will learn

  • Program GUI applications in an easy and efficient way
  • Download and install PySide, a cross-platform GUI development toolkit for Python
  • Create menus, toolbars, status bars, and child windows
  • Develop a text editor application on your own
  • Connect your GUI to a database and manage it
  • Execute SQL queries by handling databases

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 28, 2016
Length: 144 pages
Edition : 2nd
Language : English
ISBN-13 : 9781785280368
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jan 28, 2016
Length: 144 pages
Edition : 2nd
Language : English
ISBN-13 : 9781785280368
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 103.97
Pyside GUI Application Development- Second Edition
€24.99
Python 3 Object-Oriented Programming - Second Edition
€41.99
Python GUI Programming Cookbook
€36.99
Total 103.97 Stars icon

Table of Contents

7 Chapters
1. Getting Started with PySide Chevron down icon Chevron up icon
2. Entering through Windows Chevron down icon Chevron up icon
3. Main Windows and Layout Management Chevron down icon Chevron up icon
4. Events and Signals Chevron down icon Chevron up icon
5. Dialogs and Widgets Chevron down icon Chevron up icon
6. Database Handling Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.7
(3 Ratings)
5 star 0%
4 star 0%
3 star 66.7%
2 star 33.3%
1 star 0%
Amazon Customer Jan 11, 2019
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
The book is a collection of the code needed to create a basic Qt Gui. Thus the reader learns how to install PySide (on machines with the 3 main operating systems), the basic components of the QT system (such as windows, dialogs, widgets, layouts, events, signals and slots), and how to use PySide to create Gui elements that handle a database.I would prefer to see additional material on other topics such as:* What is Qt and how does PySide enhance or augment Qt* Where Python fits in the overall picture* Difference between PySide and PyQT(4 or 5)* Role or at least mention of an IDE in programming PySide* Role of Qt Designer in the overall scheme of things.But that is perhaps for another book.
Amazon Verified review Amazon
Logan Bender Jun 10, 2016
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
The examples are solid but the explanations seem a bit poor. Perhaps the Authors' non native English is to blame.If you like figuring things out yourself it's fine.If you want good, solid well written explanations and discussion of Pyside, look elsewhere.
Amazon Verified review Amazon
Nicolai Mouritzen Feb 28, 2019
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I find that better material is available for free on the internet.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.