


PyQt5 must learn the slider control QSlider_python every day
This article mainly introduces the slider control that you must learn every day in PyQt5. It has a certain reference value. Interested friends can refer to it
QSlider is a handle that can be pulled back and forth. of controls. Sometimes using a slider is more convenient than entering numbers or using a spin box.
In our example we will create a slider and a label. Label display image. The slider will control the image displayed by the label.
#!/usr/bin/python3 # -*- coding: utf-8 -*- """ PyQt5 教程 这个例子显示了一个QSlider控件的使用方法。 作者:我的世界你曾经来过 博客:http://blog.csdn.net/weiaitaowang 最后编辑:2016年8月3日 """ import sys from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QSlider from PyQt5.QtGui import QPixmap from PyQt5.QtCore import Qt 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('F:\Python\PyQt5\Widgets\images\mute.png')) self.label.setGeometry(160, 30, 80, 50) self.setGeometry(300, 300, 280, 170) self.setWindowTitle('滑块控件') self.show() def changeValue(self, value): if value == 0: self.label.setPixmap(QPixmap('F:\Python\PyQt5\Widgets\images\mute.png')) elif value > 0 and value <= 30: self.label.setPixmap(QPixmap('F:\Python\PyQt5\Widgets\images\min.png')) elif value > 30 and value < 80: self.label.setPixmap(QPixmap('F:\Python\PyQt5\Widgets\images\med.png')) else: self.label.setPixmap(QPixmap('F:\Python\PyQt5\Widgets\images\max.png')) if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
In our example, we simulate a volume control. By dragging the slider's handle, we change the image on the label.
sld = QSlider(Qt.Horizontal, self)
Create a horizontal slider QSlider
self.label = QLabel(self) self.label.setPixmap(QPixmap('F:\Python\PyQt5\Widgets\images\mute.png'))
Create a label QLabel control and Set the initial image to be displayed
sld.valueChanged[int].connect(self.changeValue)
Connect the slider's valueChanged signal to the changeValue() method (slot)
if value == 0: self.label.setPixmap(QPixmap('F:\Python\PyQt5\Widgets\images\mute.png'))
We set the image on the label based on the value of the slider. In the above code, if the slider equals zero the label's image is set to mute.png.
After the program is executed
Related recommendations:
##PyQt5 must learn the switch button every day_python
PyQT realizes multi-window switching
PyQt5 events and signals that must be learned every day
The above is the detailed content of PyQt5 must learn the slider control QSlider_python every day. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



pyqt5 installation steps: 1. Make sure that Python and pip are installed on the computer; 2. Enter the "pip install PyQt5" command in the terminal or command prompt to install PyQt5; 3. After the installation is complete, you can import the PyQt5 module in the Python script and Get started; 4. You can install some specific functions or components by entering the "pip install PyQt5.QtGui" command; 5. If you encounter any problems, you can try to upgrade pip and setuptools.

Common GUI framework PyQt5: Qt is a cross-platform C++ graphical user interface library. QT was once owned by Nokia and later sold to Digia Oyj, a Finnish software company. PyQt5 is a Python interface based on Digia's Qt5 and consists of a set of Python modules. PyQt5 itself has more than 620 classes and 6000 functions and methods. Can run on multiple platforms, including: Unix, Windows, and Mac OS. Pyside6: Pyside is the Python package officially provided by QT Company. The previous version was Pyside2, which corresponds to QT5. The naming rules of the latest version have been adjusted and changed to Pysid.

Solution: 1. Check that the Python version matches the requirements of PyQt5; 2. Install pip; 3. Install Qt; 4. Reinstall PyQt5; 5. Check whether dependencies are missing and install the missing dependencies; 6. Check for errors Message, error messages usually provide details about the problem, including missing libraries or modules; 7. Update pip and setuptools; 8. Using a virtual environment, try to install PyQt5 in a virtual environment; 9. Check the network connection; 10. Manual Download and install PyQt5.

With the popularity of web applications, rich text editors have become an indispensable tool in web development. When using Go language for web development, we also need to choose a suitable rich text editor control to enrich our websites and applications. In this article, we will discuss common rich text editor controls in Go language web development. FroalaEditorFroalaEditor is a popular rich text editor control that is widely used in web development. it has modernity

When we use the excel office software, if we can use some controls skillfully, it can help us create more professional effects in the excel form. For example, adding selection controls can make the form filler easily complete the form. Below, we will demonstrate how to make an excel selection control. We hope it will be helpful to you! 1. First, we create and open a blank excel table. 2. Add the "Development Tools" tab, click the file button on the upper left side, and find "Excel Options". After that, we find the development tools in the options of the custom ribbon and check it so that a check mark appears in front of it. 3. Return to the Excel work interface and you can see the "Development Tools" tab. Generally speaking, it is not

The steps to use the panel control are to first create a Panel control and set its width, height, background color, border color, border width and padding, create two buttons and add them to the Panel control, and finally Add the Panel control to the form.

In-depth understanding of Ajax controls: What are the common ones? Introduction: In modern Web development, Ajax (Asynchronous JavaScript and XML) has become a popular technology, which can realize partial refresh of web pages and improve user experience. In development, we usually use Ajax controls to simplify and speed up our development process. This article will take an in-depth look at Ajax controls and introduce some common controls and their functions. 1. jQueryAjax: jQueryA

Web Standard Controls Revealed: Essential Interface Elements Analysis Introduction: Web standard controls are an indispensable part of web design. They provide users with a rich interactive experience and a friendly interface, and play an important role. This article will reveal several essential Web standard controls and analyze their functions and usage methods for readers. 1. Button control Button control is one of the most common and basic elements in Web interface design, used to trigger certain operations. It usually has the following attributes: Text content: the text information displayed on the button. style
