-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1102-02-QSlider.py
More file actions
55 lines (39 loc) · 1.28 KB
/
1102-02-QSlider.py
File metadata and controls
55 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2017/11/2 下午1:14
# @Author : hukezhu
# @Site :
# @File : 1102-02-QSlider.py
# @Software: PyCharm
import sys
from PyQt5.QtWidgets import (QWidget, QSlider,QLabel,QApplication)
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
class 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[int].connect(self.changeValue)
self.label = QLabel(self)
self.label.setPixmap(QPixmap('mute.png'))
self.label.setGeometry(160,40,80,30)
self.setGeometry(300,300,280,170)
self.setWindowTitle('QSlider')
self.show()
def changeValue(self,value):
if value == 0:
self.label.setPixmap(QPixmap('mute.png'))
elif value > 0 and value <= 30:
self.label.setPixmap(QPixmap('min.png'))
elif value > 30 and value < 80:
self.label.setPixmap(QPixmap('med.png'))
else:
self.label.setPixmap(QPixmap('max.png'))
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())