# -*- coding:utf-8 -*-
'''
Created on Sep 20, 2018 @author: SaShuangYiBing Comment:
'''
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication,QWidget,QSlider,QLabel class New_test(QWidget):
def __init__(self):
super().__init__()
self.initUI() def initUI(self):
sld = QSlider(Qt.Horizontal,self)
sld.setFocusPolicy(Qt.NoFocus)
sld.setGeometry(30,55,100,30)
sld.valueChanged.connect(self.changeValue) self.label = QLabel(self)
self.label.setPixmap(QPixmap('mute.ico'))
self.label.setGeometry(160,40,80,60) self.setGeometry(300,300,280,170)
self.setWindowTitle('QSlider')
self.show() def changeValue(self,value):
if value == 0:
self.label.setPixmap(QPixmap('mute.ico'))
elif value > 0 and value <= 30:
self.label.setPixmap(QPixmap('min.ico'))
elif value > 30 and value < 80:
self.label.setPixmap(QPixmap('mid.ico'))
else:
self.label.setPixmap(QPixmap('max.ico')) if __name__ == '__main__':
app = QApplication(sys.argv)
ex = New_test()
sys.exit(app.exec_())
启动时
调节音量为小:
调节音量为中:
调节音量为大: