Python bubble tips with label

Gui updated tutorial! ! !

Today we are talking about bubble tips, it is like this.

Here Insert Picture Description

That 'This is a bubble tips' is bubble tips, be sure some friends' Oh, this is it. ', Some friends will say: "This is not a computer that comes with it." This problem when I first learned programming, as well. For example, I started to learn at first Scratch, then the goal is to compile a Zombies. When I went compile time (never learned, because it is simple, a look to understand.), Fall from the sky that the sun's effect is compiled when not compiled, but that comes with. The results also relate to what a random number, well, that far away ...

Code! ! !

import sys
from PyQt5.QtWidgets import QWidget, QToolTip, QApplication
from PyQt5.QtGui import QFont

class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.settings()

    def settings(self):
        self.setGeometry(300, 300, 400, 300)
        self.setWindowTitle('啥都行')
        self.setToolTip('气泡提示')    #气泡提示
        QToolTip.setFont(QFont('microsoft Yahei', 10))  #字体格式
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

Obviously, we setToolTip created a bubble tips. Then here to note that this is self.setToolTip, that is to say the entire interface can be displayed in bubbles, rather than buttons (talk back) on one or word then is the font. Set the font of the two parameters are the font name and size.

Just mentioned the label, that we have to talk about, as a button, a little complicated, so the next to speak the language.

Code? get out!

import sys
from PyQt5.QtWidgets import QWidget, QLabel, QApplication
from PyQt5.QtGui import QPixmap
class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.settings()

    def settings(self):
        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('啥都行')
        self.a = QLabel(self)
        self.a.setToolTip('气泡提示')
        self.a.setText('关注一下吧!')
        self.a.move(50,50)
        print(self.a.text())
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

Attention, here's bubble tip can only 'look it up' in seeing on the label outside of the label can not see the bubble tips. Perhaps some friends do not know how to see the bubble tips, is to place the cursor on the bubble tips, wait a minute to appear.

This is QLabel tab, you can also set the font. But I did not show it. self.a.text () is to obtain self.a text, if you just print self.a, then the result is:
<PyQt5.QtWidgets.QLabel Object AT 0x053A4300>
This 0x053A4300 is assigned to each execution of the program or other variable What an ID, ID is equivalent to each person's identity.

If you want to see the type of self.a, then is this:
<class 'PyQt5.QtWidgets.QLabel'>

We must note that this is very important! ! !
Content label can only be a string! ! ! , You should know that in addition to my previous blog QQ not too bold font. Why am I so seriously, we look at an example:

import sys
from PyQt5.QtWidgets import QWidget, QLabel, QApplication,QPushButton
class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('QLabel标签')
        self.a = QLabel(self)
        self.a.setText('变数字')
        self.a.move(50,50)
        self.b = QPushButton('确定',self)
        self.b.clicked.connect(self.buttonClicked)
        self.b.move(100,100)
        self.show()

    def buttonClicked(self):
        self.a.setText('123')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

It involves the button, we do not control, anyway, the next issue will tell. Probably goal is to click on the button label will become another content.

If you are using a pycharm, then click on the button will be this:
Here Insert Picture Description
If you run successful, it should be 0, but here is one. But without an error.

If you are using Sublime Text3:

Here Insert Picture Description
You do not know what's wrong. So here I am and we have repeatedly stressed:
content tags can only be a string! ! !

He went on to say. This move is to move the object to a location interface, in pixels. Tags can also be a gif or picture. gif word is used QMovie, that all of you to search, because I'm too lazy to search a gif action figure. So I just tell you that picture.

import sys
from PyQt5.QtWidgets import QWidget, QLabel, QApplication
from PyQt5.QtGui import QPixmap
class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('QLabel标签')
        self.a = QLabel(self)
        self.a.setToolTip('气泡提示')
        self.a.move(50,50)
        print(self.a.text())
        b = QLabel(self)
        b.setPixmap(QPixmap('图片名字'))
        b.move(100,100)
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

Well, this is today's Gui knowledge, if you like, might spend five seconds, plus followers, a point like this. If you have doubts, you can ask in the comments area, partners can also add my QQ: 3,418,772,261 . In the QQ, I can provide a Q & A. So the next issue goodbye, bye!

Published 21 original articles · won praise 68 · views 30000 +

Guess you like

Origin blog.csdn.net/Persia_king/article/details/105220530