此代码允许您显示滑块的值。但是,需要在代码中更改哪些内容才能无限循环地显示滑块的值呢?
主要.py
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow
from PyQt6.uic import loadUi
class SliderValue(QMainWindow):
def __init__(self):
super(SliderValue, self).__init__()
loadUi("slider_test.ui", self)
self.ui_horizontalSlider.valueChanged.connect(self.updateValue)
def updateValue(self, value):
print(value)
# Вывод в бесконечном цикле значения с ползунка
# ?? def printValueInLoop(self):
# ?? while(True):
# ?? self.updateValue()
if __name__ == '__main__':
app = QApplication(sys.argv)
SV = SliderValue()
SV.show()
sys.exit(app.exec())
slider_test.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QSlider" name="ui_horizontalSlider">
<property name="geometry">
<rect>
<x>330</x>
<y>240</y>
<width>160</width>
<height>22</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>26</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>