'TypeError in QInputDialog.getText Python

I wanted to add processing to the 'aad_player' key when clicking on the button, a 'QInputDialog' window was created, the main window opened, but only I click on 'add_player' I get an error:

TypeError: getText(QWidget, str, str, echo: QLineEdit.EchoMode = QLineEdit.Normal, text: str = '', flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags(), inputMethodHints: Union[Qt.InputMethodHints, Qt.InputMethodHint] = Qt.ImhNone): argument 1 has unexpected type 'str'
def okno_add_Player():
    Spisok = []
    foorma_spisok = 
['arrow','turtle','circle','square','triangle','classic']
    coolor_spisok = 
['dark_green','green','blue','dark_blue','purple','cayn2','gold']
    s_name, b_ok = QInputDialog.getText('Выбор гонщика', 'Введите имя 
гонщика')
    if b_ok:
        s_name = turtle.Turtle()
        Spisok.append(s_name)
        s_forma, b_ok = QInputDialog.getItem('Выбор гонщика', 
'Введите имя гонщика', foorma_spisok, editable=False)
        if b_ok:
            s_name.shape(s_forma)
            Spisok.append(s_forma)
            s_color, b_ok = QInputDialog.getItem('Выбор гонщика', 
         'Введите имя гонщика', coolor_spisok, editable=False)
            if b_ok:
                s_name.penup()
                s_name.goto(main_win, 670, 112)
                s_name.pendown()
            else:
                QMessageBox.critical('Canceled','User have clicked 
    +"Cancel"')
        else:
            QMessageBox.critical('Canceled','User have clicked 
"Cancel"')
    else:
        QMessageBox.critical('Canceled','User have clicked "Cancel"')


Solution 1:[1]

The QInputDialog methods take an optional QWidget parent as their first argument, which is why the error says that argument 1 has the wrong type (it's a str instead of a QWidget). To fix it, pass a QWidget, or None if you want the dialog to be a top-level window instead of the child of an existing window.

def okno_add_Player():
    coolor_spisok = ['dark_green','green','blue','dark_blue','purple','cayn2','gold']
    try:
        s_name, b_ok = QInputDialog.getText(None, '????? ???????', '??????? ??? ???????')
        if not b_ok:
            raise UserWarning
        s_name = turtle.Turtle()
        Spisok.append(s_name)
        s_forma, b_ok = QInputDialog.getItem(None, '????? ???????', '??????? ??? ???????', foorma_spisok, editable=False)
        if not b_ok:
            raise UserWarning
        s_name.shape(s_forma)
        Spisok.append(s_forma)
        _, b_ok = QInputDialog.getItem(None, '????? ???????', '??????? ??? ???????', coolor_spisok, editable=False)
        if not b_ok:
            raise UserWarning
        s_name.penup()
        s_name.goto(main_win, 670, 112)
        s_name.pendown()
    except UserWarning:
        QMessageBox.critical('Canceled','User have clicked "Cancel"')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Samwise