Я пытаюсь передать значение spinBox
в класс New()
, в котором функция foo()
должна к значению из spinBox
прибавлять единицу и выводить результат в label
.
Помогите дописать код.
main.py
from PyQt6.QtCore import QThread
from PyQt6.QtWidgets import QApplication, QMainWindow
from PyQt6.uic import loadUi
import sys
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
loadUi("Test.ui", self)
self.label.setText("Привет")
self.spinBox.valueChanged.connect(self.getValue)
def getValue(self):
self.value = self.spinBox.value()
print('Value : {0}'.format(self.value))
class New(QThread):
def foo(self):
''' Функция получает значение из spinBox,
прибавляет единичку и результат выводит в окно label '''
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())
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>732</width>
<height>539</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>0</y>
<width>701</width>
<height>491</height>
</rect>
</property>
<property name="title">
<string>GroupBox</string>
</property>
<widget class="QSpinBox" name="spinBox">
<property name="geometry">
<rect>
<x>520</x>
<y>190</y>
<width>131</width>
<height>61</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>110</x>
<y>190</y>
<width>341</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>732</width>
<height>26</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>