Я экспериментирую с Tkinter и MySQL на python, и у меня возникла загвоздка, с которой я не могу справиться.Весь мой код Tkinter заключен в классы, и у меня есть вызываемая функция, которая отключится и вставит новую строку в таблицу MySQL.Я хочу, чтобы сообщение отображалось в метке после завершения этой операции или при возникновении ошибки.
Вот кнопка, которая вызывает функцию. Она находится внутри класса с именем "LandingPage":
# Button to take all the user input in the entry boxes and send it to
# the addClientToDB() function that will insert them into the database.
btnAddClient = ttk.Button(addClient, text="Add Client",
command=lambda:addClientToDB(self, tbContactName.get(), tbEmailAddr.get(), tbClientCompany.get()))
# Adding the button to the grid at 3, 1, and having it span 2 columns.
# Giving it 15px padding in x and 5px in y
btnAddClient.grid(row=3, column=1, columnspan=2, padx=15, pady=5)
А вот код, который он вызывает:
# Function for adding clients to the database. It needs the name of the person,
# the email address and the company to be parsed to it
def addClientToDB(self, name, emailAddr, company):
# Creating the Connection string for the INSERT INTO statement, and adding
# the values to the end of the statement
cnxString = "INSERT INTO clientDetails(contactName, emailAddr, clientCompany)" \
"VALUES(%s, %s, %s)"
# Adding the arguments to a list that will also be sent
args = (name, emailAddr, company)
# Sending the string and the arguments off to the sendSqlQuery(), and
# putting anything that was returned into the "ans" variable
ans = sendSqlQuery(cnxString, args)
lblErrorCode.config(text=ans)
# Printing anything that was returned to the console for debugging purposes
print(ans)
Очевидно, в этом коде видно, что я пытаюсь установить метку "lblErrorCode" с помощью .config.(), но когда я запускаю код, ничего не происходит.Данные вставлены, но с Меткой ничего не происходит.Однако я получаю вывод на терминал.Итак, в качестве теста я намеренно попытался ввести слишком длинную строку, что приводит к терминалу, но ничего к метке:
1406 (22001): Data too long for column 'contactName' at row 1
Любые идеи о том, как получитьФункция обновления метки?
Заранее спасибо?