Python pyqt4 simple window layout and signal and slot (on code), pythonpyqt4

Source: Internet
Author: User

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 _())

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.