1 # -*- coding:utf-8 -*-
2 '''
3 Created on Sep 20, 2018
4
5 @author: SaShuangYiBing
6
7 Comment:
8 '''
9 import sys
10 from PyQt5.QtCore import Qt
11 from PyQt5.QtGui import QPixmap
12 from PyQt5.QtWidgets import QApplication,QWidget,QSlider,QLabel
13
14 class New_test(QWidget):
15 def __init__(self):
16 super().__init__()
17 self.initUI()
18
19 def initUI(self):
20 sld = QSlider(Qt.Horizontal,self)
21 sld.setFocusPolicy(Qt.NoFocus)
22 sld.setGeometry(30,55,100,30)
23 sld.valueChanged.connect(self.changeValue)
24
25 self.label = QLabel(self)
26 self.label.setPixmap(QPixmap('mute.ico'))
27 self.label.setGeometry(160,40,80,60)
28
29 self.setGeometry(300,300,280,170)
30 self.setWindowTitle('QSlider')
31 self.show()
32
33 def changeValue(self,value):
34 if value == 0:
35 self.label.setPixmap(QPixmap('mute.ico'))
36 elif value > 0 and value <= 30:
37 self.label.setPixmap(QPixmap('min.ico'))
38 elif value > 30 and value < 80:
39 self.label.setPixmap(QPixmap('mid.ico'))
40 else:
41 self.label.setPixmap(QPixmap('max.ico'))
42
43 if __name__ == '__main__':
44 app = QApplication(sys.argv)
45 ex = New_test()
46 sys.exit(app.exec_())
47
启动时
调节音量为小:
调节音量为中:
调节音量为大:
0