PYQT5 daily must learn slider control Qslider_python

Source: Internet
Author: User
This article mainly for you in detail the PYQT5 every day must learn slider control, with a certain reference value, interested in small partners can refer to

Qslider is a control that has a handle that can be pulled back and forth. Sometimes it is easier to use a slider than to enter a number or use a spin box.

In our example, we will create a slider and a label. The label displays the image. The slider controls the image that the label displays.

#!/usr/bin/python3#-*-coding:utf-8-*-"" "PYQT5 Tutorial This example shows how a Qslider control is used. Author: My World You've been to the blog: Http://blog.csdn.net/weiaitaowang Last edited: August 3, 2016 "" "Import sysfrom pyqt5.qtwidgets Import Qapplication, Qwidget, Qlabel, qsliderfrom Pyqt5.qtgui import qpixmapfrom pyqt5.qtcore import Qtclass Example (QWidget): D EF __init__ (self): Super (). __init__ () Self.initui () def initui (self): SLD = Qslider (Qt.horizontal, self) sld.setfocusp Olicy (Qt.nofocus) sld.setgeometry (() 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 , Self.setgeometry, 280, self.setwindowtitle (' Slider control ') 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.setPixma P (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 the volume control. By dragging the handle of the slider, 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 display

Sld.valuechanged[int].connect (Self.changevalue)

Connect the valuechanged signal of the slider 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 the zero label, the image is set to Mute.png.

After the program executes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.