使用PySide2编写GUI

时间:2019-12-15 18:42:20

标签: python pyside2

我是python的新手,试图编写一个用于计算排列的GUI应用程序。我编写了一个创建排列的函数并创建了一个界面布局ui。当我运行代码时,它会打开界面布局,但是当我通过界面传递一些数字时,会出现错误:

4 <class 'str'> <class 'int'>
<__main__.Calculator(0x1ddf232d6b0, name="MainWindow") at 0x000001DDF2C7B148> <class '__main__.Calculator'>
Traceback (most recent call last):
File "test_twst.py", line 45, in test
    self.recursion_permutations(self, int(N))
  File "test_twst.py", line 32, in recursion_permutations
    for number in range (1, N+1):
TypeError: unsupported operand type(s) for +: 'Calculator' and 'int'

请告诉我为什么行N=self.textEdit_2.toPlainText()得到字符串但是`self.recursion_permutations(self,N)``得到'Calculator'

from PySide2 import QtWidgets
from ui import Ui_MainWindow
import sys
import math

class Calculator(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.show()

        # pressed
        self.pushButton_2.clicked.connect(self.test)  


    def recursion_permutations( N:int, M = None, pref = []): 
        print(N,type(N))
        M = N if M == None else M 
        #pref = pref or []

        if M == 0:
            print(*pref, end=" ", sep="")
            return
        for number in range (1, N+1):
            if number in pref:
                continue
            pref.append(number)
            recursion_permutations(N, M-1, pref)
            pref.pop() 


    def test(self):
        #self.textEdit_2.setText("")
        N=self.textEdit_2.toPlainText()
        print (N,type(N))
        self.recursion_permutations(self, N)
        #self.textEdit_2.setText(str([*stroki]))    


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    calc = Calculator()
    sys.exit(app.exec_())

0 个答案:

没有答案