In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use the slider control QSlider in PyQt5. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
QSlider is a control with a handle that pulls back and forth. Sometimes it is more convenient to use the slider than to enter a number or use a swivel box.
In our example, we will create a slider and a label. The label displays the image. The slider controls the image displayed by the label.
#! / usr/bin/python3#-*-coding: utf-8-*-import sysfrom PyQt5.QtWidgets import QApplication, QWidget, QLabel, QSliderfrom PyQt5.QtGui import QPixmapfrom PyQt5.QtCore import Qtclass Example (QWidget): def _ init__ (self): super (). _ init__ () self.initUI () def initUI (self): sld = QSlider (Qt.Horizontal, self) sld.setFocusPolicy (Qt.NoFocus) sld.setGeometry (30,40,100) 30) sld.valueChanged.connect (self.changeValue) self.label = QLabel (self) self.label.setPixmap (QPixmap ('F:\ Python\ PyQt5\ Widgets\ images\ mute.png')) self.label.setGeometry (160,30,80,50) self.setGeometry (300,300,280,170) self.setWindowTitle ('slider control') self.show () def changeValue (self) Value): if value = = 0: self.label.setPixmap (QPixmap ('F:\ Python\ PyQt5\ Widgets\ images\ mute.png')) elif value > 0 and value 30 and value
< 80: self.label.setPixmap(QPixmap('F:\Python\PyQt5\Widgets\images\med.png')) else: self.label.setPixmap(QPixmap('F:\Python\PyQt5\Widgets\images\max.png'))if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) 在我们的例子中,我们模拟音量控制。通过拖动滑块的手柄,我们改变标签上的图像。 sld = QSlider(Qt.Horizontal, self) 创建一个水平滑块 QSlider self.label = QLabel(self)self.label.setPixmap(QPixmap('F:\Python\PyQt5\Widgets\images\mute.png')) 创建一个标签 QLabel 控件并设置要显示的初始图像 sld.valueChanged[int].connect(self.changeValue) 将滑块的 valueChanged 信号连接到 changeValue() 方法(槽) if value == 0: self.label.setPixmap(QPixmap('F:\Python\PyQt5\Widgets\images\mute.png')) 我们根据滑块的值设置标签上的图像。在上面的代码中,如果滑块等于零标签的图像设置为mute.png。 程序执行后This is the end of this article on "how to use the slider control QSlider in PyQt5". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.