Home Backend Development Python Tutorial PyQt5 must learn the pop-up message box every day

PyQt5 must learn the pop-up message box every day

Apr 19, 2018 am 11:23 AM
pyqt5 pop up information

This article mainly introduces in detail the pop-up message box that you must learn every day in PyQt5. It has a certain reference value. Interested friends can refer to it

By default, if we click on the title X button on the bar, the QWidget closes. Sometimes, we need to change this default behavior. For example, if we have a file that we want to open in an editor, we can first display a message box to confirm the open or not operation.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

#!/usr/bin/python3

# -*- coding: utf-8 -*-

 

"""

PyQt5 教程

 

当我们点击应用程序窗口的关闭按钮,该程序显示一个确认信息框。

 

作者:我的世界你曾经来过

博客:http://blog.csdn.net/weiaitaowang

最后编辑:2016年7月29日

"""

 

import sys

from PyQt5.QtWidgets import QApplication, QWidget, QMessageBox

 

class Example(QWidget):

 

 def __init__(self):

  super().__init__()

 

  self.initUI()

 

 def initUI(self):

 

  self.setGeometry(300, 300, 300, 220)

  self.setWindowTitle('消息盒子') 

  self.show()

 

 def closeEvent(self, event):

 

  reply = QMessageBox.question(self, '信息', '确认退出吗?',

   QMessageBox.Yes | QMessageBox.No, QMessageBox.No)

 

  if reply == QMessageBox.Yes:

   event.accept()

  else:

   event.ignore()

 

if __name__ == '__main__':

 

 app = QApplication(sys.argv)

 ex = Example()

 sys.exit(app.exec_())

Copy after login

If we close the QWidget control, the QCloseEvent event will be generated. To modify the control properties we need to reimplement the closeEvent() event handler.

1

2

reply = QMessageBox.question(self, '信息', '确认退出吗?',

  QMessageBox.Yes | QMessageBox.No, QMessageBox.No)

Copy after login

We display a message box with two buttons: Yes and No. The first string appears in the title bar. The second string is the message text displayed in the dialog box. The third parameter specifies the button combination in the pop-up dialog box. The last parameter is the default button, which is the button with initial keyboard focus. The return value is stored in the reply variable.

1

2

3

4

if reply == QMessageBox.Yes:

  event.accept()

 else:

  event.ignore()

Copy after login

Here we use if to test the return value. If we click the Yes button, we accept the closing of the button control and execute the application's terminate event. Otherwise, we ignore the closing event.

After the program is executed, click the ##PyQt5 realizes the download progress bar effect

PyQt5 must learn the pop-up message box every dayPyQt5 must learn the pop-up message box every dayPyQt5 must learn the progress bar effect every day


PyQt5 must learn every day QSplitter implements window separation

The above is the detailed content of PyQt5 must learn the pop-up message box every day. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to swipe right and reply quickly in iMessage on iOS 17 How to swipe right and reply quickly in iMessage on iOS 17 Sep 20, 2023 am 10:45 AM

How to Use Swipe to Reply in iMessages on iPhone Note: The Swipe to Reply feature only works with iMessage conversations in iOS 17, not regular SMS conversations in the Messages app. Open the Messages app on your iPhone. Then, head to the iMessage conversation and simply swipe right on the iMessage you want to reply to. Once this is done, the selected iMessage will be in focus while all other messages will be blurred in the background. You'll see a text box for typing a reply and a "+" icon for accessing iMessage apps like Check-ins, Places, Stickers, Photos, and more. Just enter your message,

What does it mean when a message has been sent but rejected by the other party? What does it mean when a message has been sent but rejected by the other party? Mar 07, 2024 pm 03:59 PM

The message has been sent but rejected by the other party. This means that the sent information has been successfully sent from the device, but for some reason, the other party did not receive the message. More specifically, this is usually because the other party has set certain permissions or taken certain actions, which prevents your information from being received normally.

iOS 17: How to use emojis as stickers in Messages iOS 17: How to use emojis as stickers in Messages Sep 18, 2023 pm 05:13 PM

In iOS17, Apple has added several new features to its Messages app to make communicating with other Apple users more creative and fun. One of the features is the ability to use emojis as stickers. Stickers have been around in the Messages app for years, but so far, they haven't changed much. This is because in iOS17, Apple treats all standard emojis as stickers, allowing them to be used in the same way as actual stickers. This essentially means you're no longer limited to inserting them into conversations. Now you can also drag them anywhere on the message bubble. You can even stack them on top of each other to create little emoji scenes. The following steps show you how it works in iOS17

How to install pyqt5 How to install pyqt5 Nov 30, 2023 pm 02:05 PM

pyqt5 installation steps: 1. Make sure that Python and pip are installed on the computer; 2. Enter the "pip install PyQt5" command in the terminal or command prompt to install PyQt5; 3. After the installation is complete, you can import the PyQt5 module in the Python script and Get started; 4. You can install some specific functions or components by entering the "pip install PyQt5.QtGui" command; 5. If you encounter any problems, you can try to upgrade pip and setuptools.

The message has been sent but was rejected by the other party. Should I block it or delete it? The message has been sent but was rejected by the other party. Should I block it or delete it? Mar 12, 2024 pm 02:41 PM

1. Being added to the blacklist: The message has been sent but rejected by the other party. Generally, you have been blacklisted. At this time, you will not be able to send messages to the other party, and the other party will not be able to receive your messages. 2. Network problems: If the recipient's network condition is poor or there is a network failure, the message may not be successfully received. At this point, you can try to wait for the network to return to normal before sending the message again. 3. The other party has set up Do Not Disturb: If the recipient has set up Do Not Disturb in WeChat, the sender’s messages will not be reminded or displayed within a certain period of time.

Super complete! Python graphical interface framework PyQt5 usage guide! Super complete! Python graphical interface framework PyQt5 usage guide! Apr 13, 2023 am 08:43 AM

Common GUI framework PyQt5: Qt is a cross-platform C++ graphical user interface library. QT was once owned by Nokia and later sold to Digia Oyj, a Finnish software company. PyQt5 is a Python interface based on Digia's Qt5 and consists of a set of Python modules. PyQt5 itself has more than 620 classes and 6000 functions and methods. Can run on multiple platforms, including: Unix, Windows, and Mac OS. Pyside6: Pyside is the Python package officially provided by QT Company. The previous version was Pyside2, which corresponds to QT5. The naming rules of the latest version have been adjusted and changed to Pysid.

How to set up Xiaomi Mi 14 Pro to light up the screen for messages? How to set up Xiaomi Mi 14 Pro to light up the screen for messages? Mar 18, 2024 pm 12:07 PM

Xiaomi 14Pro is a flagship model with excellent performance and configuration. It has achieved high sales since its official release. Many small functions of Xiaomi 14Pro will be ignored by everyone. For example, it can be set to light up the screen for messages. Although the function is small, , but it is very practical. Everyone will encounter various problems when using the mobile phone. So how to set up the Xiaomi 14Pro to light up the screen for messages? How to set up Xiaomi Mi 14 Pro to light up the screen for messages? Step 1: Open your phone’s Settings app. Step 2: Swipe down until you find the "Lock screen and password" option and click to enter. Step 3: In the "Lock screen & passcode" menu, find and click the "Turn on screen for notifications" option. Step 4: On the "Turn on screen when receiving notifications" page, turn on the switch to enable

How to edit messages on iPhone How to edit messages on iPhone Dec 18, 2023 pm 02:13 PM

The native Messages app on iPhone lets you easily edit sent texts. This way, you can correct your mistakes, punctuation, and even autocorrect wrong phrases/words that may have been applied to your text. In this article, we will learn how to edit messages on iPhone. How to Edit Messages on iPhone Required: iPhone running iOS16 or later. You can only edit iMessage text on the Messages app, and then only within 15 minutes of sending the original text. Non-iMessage text is not supported, so they cannot be retrieved or edited. Launch the Messages app on your iPhone. In Messages, select the conversation from which you want to edit the message

See all articles