datetime:2019/5/21 15:44
author:nzb
创建滑动条
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QGroupBox, QCheckBox, \
QHBoxLayout, QPushButton, QButtonGroup, QFrame, QSlider
from PyQt5.QtWidgets import QSplitter, QLineEdit
from PyQt5 import QtGui, QtCore
from PyQt5.QtCore import Qt
class UI_demo(QWidget):
"""用户界面"""
def __init__(self):
super().__init__()
self.title = 'PyQt5 Slider'
self.left = 600
self.top = 200
self.width = 500
self.height = 500
self.iconName = '../img/home.ico'
self.initWindow()
def initWindow(self):
self.setWindowIcon(QtGui.QIcon(self.iconName))
self.setGeometry(self.left, self.top, self.width, self.height)
self.setWindowTitle(self.title)
self.setStyleSheet('background-color:yellow')
hbox = QHBoxLayout()
self.slider = QSlider()
self.slider.setOrientation(Qt.Horizontal)
self.slider.setTickPosition(QSlider.TicksBelow)
self.slider.setTickInterval(10)
self.slider.setMinimum(0)
self.slider.setMaximum(100)
self.slider.valueChanged.connect(self.changedValue)
self.label = QLabel('0')
self.label.setFont(QtGui.QFont('Sanserif', 15))
hbox.addWidget(self.slider)
hbox.addWidget(self.label)
self.setLayout(hbox)
self.show()
def changedValue(self):
size = self.slider.value()
self.label.setText(str(size))
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = UI_demo()
sys.exit(app.exec_())