📜  PyQt5 – QDial

📅  最后修改于: 2022-05-13 01:54:53.370000             🧑  作者: Mango

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())

输出 :