Rechercher
 

Utilisation d'un widget QSlider

 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 
#!/usr/bin/python3
# -*- coding : utf-8 -*-

import sys
from PyQt5.Qt import *

class MyWindow(QMainWindow):
    
    def __init__ (self) :
        QMainWindow.__init__( self )
        self.setWindowTitle( 'QT Slider with Python' )
        self.resize(320, 150)
    
        self.__slider = QSlider( Qt.Horizontal, self )
        self.__slider.setGeometry( 10, 10, 300, 40 )
        self.__slider.valueChanged.connect( self.valueChanged )
        
        self.__button = QPushButton("Reset slider value", self)
        self.__button.setGeometry(10, 50, 230, 35)
        self.__button.clicked.connect( self.resetValue )
        
        self.__label = QLabel( self )
        self.__label.setGeometry(250, 50, 50, 35)
        
        
    def valueChanged( self, value ):
        self.__label.setText( str( value ) )
    
    def resetValue(self):
        self.__slider.setValue( 0 )


if __name__ == "__main__" :
    app = QApplication( sys.argv )

    myWindow = MyWindow()
    myWindow.show()
    
    sys.exit( app.exec_() )
Utilisation d'un widget QSlider

Voici le résultat produit par cette application.