PyQt5 QDial
QDial 是PyQt5中的一个类,它为用户提供了在程序定义的范围内选择数值的功能,并且这个范围是环绕的(例如,角度从0到359度)。此外,它还可以用类似于速度表的方式来显示当前值。下面是QDial的外观
例子:
一个有QDial的窗口,用户可以改变它的数值,当用户改变数值时,当前的数值将显示在标签上。
以下是实现的过程
# importing libraries
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
class Window(QMainWindow):
def __init__(self):
super().__init__()
# setting title
self.setWindowTitle("Python ")
# setting geometry
self.setGeometry(100, 100, 500, 400)
# calling method
self.UiComponents()
# showing all the widgets
self.show()
# method for components
def UiComponents(self):
# creating QDial object
dial = QDial(self)
# setting geometry to the dial
dial.setGeometry(100, 100, 100, 100)
# adding action to the dial
dial.valueChanged.connect(lambda: dial_method())
# creating a label
label = QLabel("GeeksforGeeks", self)
# setting geometry to the label
label.setGeometry(220, 125, 200, 60)
# making label multiline
label.setWordWrap(True)
# method called by the dial
def dial_method():
# getting dial value
value = dial.value()
# setting text to the label
label.setText("Current Value : " + str(value))
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())