

When we create a QApplication object we pass it the command-line arguments this is because PyQt recognizes some command-line arguments of its own, such as -geometry and -style, so we ought to give it the chance to read them. This object also provides the event loop, discussed shortly.

This object provides access to global-like information such as the application's directory, the screen size (and which screen the application is on, in a multihead system), and so on. Every PyQt GUI application must have a QApplication object. We begin by creating a QApplication object.

The time module is imported because we need its sleep() function, and we need the PyQt modules for the GUI and for the QTime class. We import the sys module because we want to access the command-line arguments it holds in the sys.argv list. Import sys import time from PyQt4.QtCore import * from PyQt4.QtGui import * The file is a few lines longer than 25 lines because we have not counted comment lines and blank lines in the total-but there are only 25 lines of executable code.
#Pyqt popup window how to#
Now that we know what it does and how to run it, we will review the implementation. For testing purposes we can use a time that has just gone for example, by using 12:15 when it is really 12:30, the window will pop up immediately (well, within less than a second). The specified time must use the 24-hour clock. About a minute after showing the window, the application will automatically terminate. At that point, it pops up a window with the message text. When run, the program executes invisibly in the background, simply marking time until the specified time is reached. Figure 4.1 shows the whole thing.įigure 4.1 The Alert program To get the output displayed, we could enter a command line like this:Ĭ:\>cd c:\pyqt\chap04 C:\pyqt\chap04>alert.pyw 12:15 Wake Up First, it must be run from the console, and second it has no "decorations"-no title bar, no system menu, no X close button.
