J
J
Just2019-12-01 22:00:53
Python
Just, 2019-12-01 22:00:53

What did I do wrong (python 3)?

I'm just learning Python 3.
In general, I don't understand why it doesn't work, this approach works in the console program, but not in the gui :(
Help me understand what I'm doing wrong ..

from PyQt5 import QtWidgets, QtGui
from gui2 import Ui_MainWindow #Импорт GUI
import sys


class MyWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(MyWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setWindowIcon(QtGui.QIcon('uppelower.ico'))
        self.ui.pushButton_4.clicked.connect(self.Copy)
        self.ui.pushButton.clicked.connect(self.Upper)
        self.ui.pushButton_2.clicked.connect(self.Lower)
        self.ui.textEdit.textChanged.connect(self.CountText)

    def Copy(self):
        self.ui.textEdit.selectAll()
        self.ui.textEdit.copy()

    def Upper(self):
        up = self.ui.textEdit.toPlainText()
        self.ui.textEdit.setPlainText(str(up).upper())

    def Lower(self):
        low = self.ui.textEdit.toPlainText()
        self.ui.textEdit.setPlainText(str(low).lower())


#---- Вот эта часть кода

    def CountText(self):
        TextChanged = self.ui.textEdit.toPlainText()
        self.ui.identical.setText(str(TextChanged).count(' ') + 1)
        self.ui.identical.adjustSize()

# ---- не работает

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = MyWindow()
    window.show()
    sys.exit(app.exec_())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
al, 2019-12-02
Anonymous @skorbot

Try to walk the debugger through the function to understand exactly where the error is. It seems to me that the reason is in 1 type int. Make a '1'.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question