PyQt5 QDoubleSpinBox – 设置前缀
在本文中,我们将看到如何为 QDoubleSpinBox 设置前缀。前缀是放在词干之前的词缀。将其添加到一个单词的开头会将其更改为另一个单词。例如,当前缀 un- 被添加到单词 happy 时,它会创建单词 unhappy。可以在双旋转框值的前面添加一个字符串。
In order to do this we will use setPrefix
method with the double spin box object.
Syntax : dd_spin.setPrefix(text)
Argument : It takes string as argument
Return : It returns None
下面是实现
# 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 double spin box
d_spin = QDoubleSpinBox(self)
# setting geometry to the double spin box
d_spin.setGeometry(100, 100, 150, 40)
# setting prefix
d_spin.setPrefix("Value : ")
# step type
step_type = QAbstractSpinBox.AdaptiveDecimalStepType
# adaptive step type
d_spin.setStepType(step_type)
# creating a label
label = QLabel("GeeksforGeeks", self)
# setting geometry to the label
label.setGeometry(100, 200, 300, 80)
# making label multi line
label.setWordWrap(True)
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
输出 :