Python pyqt4 simple window layout and signal and slot (on code), pythonpyqt4
#-*-Coding: UTF-8 -*-
Import sys
Reload (sys)
Sys. setdefaultencoding ('utf8 ')
From PyQt4 import QtGui, QtCore
'''App = QtGui. QApplication (sys. argv)
W = QtGui. QWidget ()
W. resize (300,250)
W. move (1, 200,100)
W. setWindowTitle ('code10 ')
W. show ()
Sys.exit(app.exe c _())'''
Class Index (QtGui. QWidget ):
Def _ init _ (self, parent = None ):
QtGui. QWidget. _ init _ (self, parent)
# Set the window size and position
Self. setGeometry (600,100,400,650)
# Set window name
Self. setWindowTitle (u'code Code ')
# Setting window icons
Self. setw.wicon (QtGui. QIcon ('../pic/0321.png '))
# Set the window prompt (the Code does not work)
# Self. setToolTip (u'this is a <B> QWidget </B> widget ')
# QtGui. QToolTip. setFont (QtGui. QFont ('oldenglish ', 20 ))
# Create button
Quit = QtGui. QPushButton (U' click to close ', self)
# Create button position
Quit. setGeometry (0, 0, 60, 35)
# Click the button to close (The Event Processing System of PyQt4 is built on the signal-slot mechanism)
Self. connect (quit, QtCore. SIGNAL ('clicked () '), QtGui. qApp, QtCore. SLOT ('Quit ()'))
# How to close the window
Def closeEvent (self, event ):
# Close the closeEvent Method
Reply = QtGui. QMessageBox. question (self, U' hint ', u "are you sure you want to disable it? ", QtGui. QMessageBox. Yes, QtGui. QMessageBox. No)
# The first string parameter is displayed in the title bar of the message window,
# The second string parameter 1 dialog is displayed in the message window.
# The returned results are saved in the reply variable.
If reply = QtGui. QMessageBox. Yes:
# Agree
Event. accept ()
Else:
# Ignore
Event. ignore ()
App = QtGui. QApplication (sys. argv)
Index = Index ()
Index. show ()
Sys.exit(app.exe c _())