Home arrow Python arrow Page 2 - PyQT: Handling Windows and Buttons

Slots - Python

In this article, you will continue to learn about the process of building a GUI in PyQT. Specifically, you will learn about QDialog and QPushButton, which handle windows and buttons, the building blocks of most GUIs.

  1. PyQT: Handling Windows and Buttons
  2. Slots
  3. QPushButton
  4. PyQT in the Real World
By: A.P.Rajshekhar
Rating: starstarstarstarstar / 8
April 05, 2006

print this article



The show() and exec_loop() methods determine whether the dialogs are modal  or modeless. However the main purpose of dialogs is to provide information feedback to the user, as well as to gather information from the user using buttons such as OK and Cancel. For these purposes, the accept() and reject() slots have been provided by the QDialog class. 

Both of these are protected Slots. They are available only to the classes inherited from QDialog.

The accept() slot closes the dialog and sets the return value to ACCEPTED. This value is equivalent to the Boolean value of 1. The best scenario to visualize the usage of accept() is a button representing OK. If the clicked signal of this button is connected with the accept() slot, then upon the button being clicked, the dialog box would be closed and the return value would become ACCEPTED. In code this would be:

       self.OK = QPushButton(self,"OK")

The above code is a snippet from an about dialog. When the OK button is clicked, the signal connects to the accept() dialog.

The reject() slot provides functionalities that are the opposite of accept(). It comes into picture when the dialog is canceled. The return code is set to Rejected. This slot can be connected to the signal corresponding to the dialog box or any button's clicked() signal. If the button's clicked() signal is connected, then the code would be:       

self.Cancel = QPushButton(self,"Cancel")

QDialog (as of version 3.x) doesn't emit any signal of its own.  That's about it for QDialog and its main slots and methods. Next is the most common widget of all: the command button, or in the terminology of PyQT, QPushButton. 

>>> More Python Articles          >>> More By A.P.Rajshekhar

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates


Dev Shed Tutorial Topics: