У меня есть этот код для переключения между меню
import sys
from PyQt5.QtCore import (QCoreApplication, QMetaObject, QObject, QPoint,
QRect, QSize, QUrl, Qt)
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtCore
from PyQt5.QtCore import QPropertyAnimation, QPoint
from PyQt5.QtWidgets import QGraphicsEffect, QApplication, QWidget, QMainWindow, QVBoxLayout, QLabel
'''
from PySide2.QtCore import (QCoreApplication, QMetaObject, QObject, QPoint,
QRect, QSize, QUrl, Qt)
from PySide2 import QtWidgets
from PySide2 import QtGui
from PySide2 import QtCore
from PySide2.QtCore import QPropertyAnimation, QPoint
from PySide2.QtWidgets import QGraphicsEffect, QApplication, QWidget, QMainWindow, QVBoxLayout, QLabel
'''
class Main(QtWidgets.QWidget):
def __init__(self):
super().__init__()
center_lay = QtWidgets.QGridLayout(self)
center_lay.setObjectName(u"center_lay")
Spacer_1 = QtWidgets.QSpacerItem(17, 105, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
center_lay.addItem(Spacer_1, 0, 1, 1, 1)
Spacer_2 = QtWidgets.QSpacerItem(327, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
center_lay.addItem(Spacer_2, 1, 0, 1, 1)
Spacer_3 = QtWidgets.QSpacerItem(326, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
center_lay.addItem(Spacer_3, 1, 2, 1, 1)
Spacer_4 = QtWidgets.QSpacerItem(20, 105, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
center_lay.addItem(Spacer_4, 2, 1, 1, 1)
block = QtWidgets.QWidget()
block.setObjectName(u"block")
center_lay.addWidget(block, 1, 1, 1, 1)
block.setMinimumSize(QSize(300, 300))
lay_block = QtWidgets.QVBoxLayout(block)
lay_block.setObjectName(u"lay_block")
block.setStyleSheet('''background:#000''')
self.mv_blur_but = QtWidgets.QWidget(block)
self.mv_blur_but.setObjectName(u"mv_blur_but")
self.mv_blur_but.setGeometry(QRect(110, 20, 111, 111))
self.mv_blur_but.setStyleSheet('''background:#fff''')
move_blur_button_lay = QtWidgets.QVBoxLayout(self.mv_blur_but)
move_blur_button_lay.setObjectName(u"move_blur_button_lay")
self.mv_rad_arr = []
self.mv_cont_arr = []
for x in range(2):
radio = QtWidgets.QRadioButton(self.mv_blur_but)
radio.setObjectName("mv_radio_but-{}".format(x))
radio.pressed.connect(self.off)
radio.toggled.connect(self.anim )
self.mv_rad_arr.append(radio)
move_blur_button_lay.addWidget(self.mv_rad_arr[x])
mv_blur_menu = QtWidgets.QWidget(block)
mv_blur_menu.resize(50, 60)
mv_blur_menu.move(60 , 20)
self.mv_cont_arr.append(mv_blur_menu)
but = self.mv_rad_arr[x]
menu = self.mv_cont_arr[x]
self.mv_cont_arr[0].setStyleSheet('''background:#ff0''')
self.mv_cont_arr[1].setStyleSheet('''background:#f0f''')
self.radio_1 = QtWidgets.QRadioButton(self.mv_blur_but)
self.radio_1.setObjectName("mv_radio_but-99")
self.radio_1.move(-self.radio_1.width(),0)
self.mv_rad_arr.append(self.radio_1)
self.group = QtCore.QSequentialAnimationGroup(self)
self.num = 0
self.menu_group_ani = []
def anim (self):
self.animation= []
for i in range(2):
menuAnimation = QtCore.QVariantAnimation() #Fun Animation
menuAnimation.setDuration(500) #Time
menuAnimation.setEasingCurve(QtCore.QEasingCurve.OutQuart)
menuAnimation.setStartValue(QPoint(-20, 10))
menuAnimation.setEndValue(QPoint(0, 10))
self.animation.append(menuAnimation)
self.num =self.num+1
old = int(self.sender().objectName().split('-')[1])
self.menu_group_ani.append(old)
print(self.menu_group_ani)
ff_id = 0
for id in sorted(self.menu_group_ani):
pos1 = QPoint(60 , 20)
pos2 = QPoint(221, 20)
self.animation[ff_id].setStartValue(pos1)
self.animation[ff_id].setEndValue(pos2)
self.animation[ff_id].valueChanged.connect(lambda value, val=self.menu_group_ani[ff_id]: self.chengeval(value, val))
self.mv_cont_arr[self.menu_group_ani[0]].raise_()
self.mv_blur_but.raise_()
if self.mv_cont_arr[self.menu_group_ani[ff_id]].pos() == pos2:
self.animation[ff_id].setDirection(QtCore.QAbstractAnimation.Backward)
else :
self.animation[ff_id].setDirection(QtCore.QAbstractAnimation.Forward)
ff_id +=1
try:
self.animation[0].finished.connect(self.animation[1].start)
except IndexError:
print('Err')
if (self.num == 1) or (self.num == 3):
self.menu_group_ani.clear()
self.animation[0].start()
if self.num == 3 :
self.num = 1
def off(self):
check_1 = self.sender().isChecked()
if check_1 == True:
print('check')
self.radio_1.setChecked(True) #Unchecked/Checked
self.menu_group_ani.clear()
else:
print('uncheked')
def chengeval(self,value,val=''):
self.mv_cont_arr[val].move(value.x(), value.y())
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
win = Main()
win.resize(640, 570)
win.show()
sys.exit(app.exec_())
все работает хорошо, пока я не выключу его (само) почему код так нестабилен?
проблема
мне нужно
Я пытался работать с self.menu_group_ani, используя clear () или, если что-то, что я делаю, код не работает правильно, clicked.connect также не дал желаемого результата. Как это исправить?