Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to display the prompt box in pyqt5 in Python

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article to share with you is about Python pyqt5 how to display the prompt box, Xiaobian feel very practical, so share to everyone to learn, I hope you can read this article after some gains, not much to say, follow Xiaobian to see it.

The most basic pyqt5 code

import sys

from PyQt5.QtWidgets import QApplication,QWidget

if __name__=="__main__":

app=QApplication(sys.argv)

w=QWidget()

w.show()

app.exec_()

II. Display prompt box

We use the function setToolTip

Note: Basically all controls, including forms, have the setToolTip function, which means that this function basically has.

Use format:

Control object.setToolTip (here is the string to prompt)

II. Button controls

In fact, each control is a class library, including button controls.

We have button controls here, we use the class QPushButton

Basic use:

Instantiate a button example

btn=QPushButton("Lao Liu",w)

Use format:

Declarations define the name of an instantiated object = QPushButton(button literal, parent container)

We can control the button's position in the parent container by using the button's move function.

III. File Search Skills in the System

We can search all files containing the keyword ToolTip using *ToolTip*

The * asterisk here stands for all, indicating any number of characters.

How do I find the class I need?

1. We can find the corresponding pyqt5 file installation location by right-clicking the code above pycharm

2. Use fuzziness to find the location of the class we need in pyqt5

3. Import found classes into program

Display Box Text Style Settings:

1. Need to import QToolTip library

2. Set text style via setFont method of QToolTip

3. Need to import QFont class library

4. Instantiate QFont class for text styling

5. The settings for this display style are those that render effects in global styles

IV. Summary and emphasis

1. Master the basics pyqt5 code gui writing

2. Master Display Box Settings setToolTip function

3. Master Display Box Text Style Settings

4. Master the code writing ideas

Source code for this section:

import sysfrom PyQt5.QtWidgets import QApplication,QWidget,QPushButton,QToolTipfrom PyQt5.QtGui import QIcon,QFont

if __name__=="__main__": app=QApplication(sys.argv)

w=QWidget() w.setWindowTitle("Liu Jinyu Programming")

app.setWindowIcon(QIcon("./ img/liu.png")) w.setToolTip("Programming Cities bcczcs.com")

#Button btn=QPushButton("Lao Liu",w) btn.move(50,50) btn.setToolTip("Hello, Liu Jinyu")

w.resize(400,300) w.show()

QToolTip.setFont(QFont("Lishu", 40)) app.exec_() The above is how pyqt5 displays the prompt box in Python. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report