Alright, let me explain what is happening I am using a tkinter form and am taking the information being filled out and I am selecting information from a database containing films. I have written this code twice, it was written once without the information being taken from a tkinter form, and it was then written a second time with the information being taken from a tkinter form. I am uncertain where the error is from as the code hasn't been altered.
This is the code that is functioning properly:
def PersonalityQuiz():
QuizUI = tk.Tk()
QuizUI.title("Personality Quiz")
QuizUI.geometry('700x300')
firstname = input("What is your first name?")
surname = input("What is your surname?")
answer1 = q1()
answer2 = q2()
answer3 = q3()
answer4 = q4()
answer5 = q5()
print(answer4,answer5)
sql = "SELECT * FROM Movies WHERE PG_Rating <= %s AND Minutes <= %s AND Year >= %s AND Genre = %s AND Sub_Genre = %s ORDER BY imdb desc"
statement = (answer1,answer2,answer3,answer4,answer5)
SQLFilmID = "SELECT FilmID FROM Movies WHERE PG_Rating <= %s AND Minutes <= %s AND Year >= %s AND Genre = %s AND Sub_Genre = %s"
mycursor = mydb.cursor()
mycursor.execute(sql,statement)
myresult = mycursor.fetchall()
listbox = tk.Listbox(QuizUI)
listbox.pack()
for i in myresult:
listbox.insert(tk.END, i)
mycursor.execute(SQLFilmID,statement)
FilmID = mycursor.fetchall()
SQLinsert = "INSERT INTO users (FirstName, Surname) VALUES (%s,%s)"
vals = (firstname,surname)
mycursor.execute(SQLinsert,vals)
mydb.commit()
UserID = mycursor.lastrowid
for i in FilmID:
LinkInsert = "INSERT INTO userlink (UserID, FilmID) VALUES (%s,%s)"
vals = (str(UserID), str(i[0]))
mycursor.execute(LinkInsert, vals)
mydb.commit()
QuizUI.mainloop()
Here is the errorous code:
def guiform():
genres = [
"Action",
"Adventure",
"Animation",
"Comedy",
"Crime",
"Documentry",
"Drama",
"Family",
"Fantasy",
"Horror",
"Musical",
"Sci-Fi",
"Spy",
"Superhero",
"War",
] #etc
guitest = tk.Tk()
guitest.geometry("700x400")
frame1 = tk.Frame(master=guitest, height=200, width=100, bg="crimson")
frame1.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
values = tk.StringVar(guitest)
values.set(genres[0]) # default value
lblfirstname = tk.Label(frame1, text="First Name")
lblfirstname.grid(row=1,column=2)
ENTfirstname = tk.Entry(frame1)
ENTfirstname.grid(row=2,column=2)
lblsurname = tk.Label(frame1, text="Surname")
lblsurname.grid(row=3,column=2)
ENTsurname = tk.Entry(frame1)
ENTsurname.grid(row=4,column=2)
lbl1 = tk.Label(frame1, text="How old are you?")
lbl1.grid(row=1,column=0)
question1 = tk.Entry(frame1)
question1.grid(row=2,column=0)
lbl2 = tk.Label(frame1, text="What is the longest you would want a film to be? (minutes)")
lbl2.grid(row=4,column=0)
question2 = tk.Entry(frame1)
question2.grid(row=5,column=0)
lbl3 = tk.Label(frame1, text="What is the oldest year you would watch a movie from (e.g. 1985)")
lbl3.grid(row=6,column=0)
question3 = tk.Entry(frame1)
question3.grid(row=7,column=0)
lbl4 = tk.Label(frame1, text="What is your preferred Genre?")
lbl4.grid(row=8,column=0)
w = tk.OptionMenu(frame1, values, *genres)
w.grid(row=9, column=0)
submit = tk.Button(frame1, text="Submit information", command=lambda:infoget(question1.get,question2.get(),question3.get(),values.get()),width=18)
submit.grid(column=0, row=10)
listbox=tk.Listbox(frame1)
listbox.grid(row=0,column=1, rowspan=10)
def infoget(answer1,answer2,answer3,answer4):
sql = "SELECT * FROM Movies WHERE PG_Rating <= %s AND Minutes <= %s AND Year >= %s AND Genre = %s ORDER BY imdb desc"
statement = (answer1,answer2,answer3,answer4)
mycursor = mydb.cursor()
mycursor.execute(sql, statement)
myresult = mycursor.fetchall()
for i in myresult:
listbox.insert(tk.END, i)
SQLFilmID = "SELECT FilmID FROM Movies WHERE PG_Rating <= %s AND Minutes <= %s AND Year >= %s AND Genre = %s ORDER BY imdb desc"
mycursor.execute(SQLFilmID,statement)
FilmID = mycursor.fetchall()
SQLinsert = "INSERT INTO users (FirstName, Surname) VALUES (%s,%s)"
vals = (str(firstname),str(surname))
mycursor.execute(SQLinsert,vals)
mydb.commit()
#Returns the Primary Key of the last row accessed by the SQL cursor
UserID = mycursor.lastrowid
for i in FilmID:
LinkInsert = "INSERT INTO userlink (UserID, FilmID) VALUES (%s,%s)"
vals = (str(UserID), str(i[0]))
mycursor.execute(LinkInsert, vals)
mydb.commit()
guitest.update
guitest.mainloop()
And this is the lovely error that it produces:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:UserslupinAppDataLocalProgramsPythonPython39libsite-packagesmysqlconnectorconversion.py", line 183, in to_mysql
return getattr(self, "_{0}_to_mysql".format(type_name))(value)
AttributeError: 'MySQLConverter' object has no attribute '_method_to_mysql'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UserslupinAppDataLocalProgramsPythonPython39libsite-packagesmysqlconnectorcursor.py", line 432, in _process_params
res = [to_mysql(i) for i in res]
File "C:UserslupinAppDataLocalProgramsPythonPython39libsite-packagesmysqlconnectorcursor.py", line 432, in <listcomp>
res = [to_mysql(i) for i in res]
File "C:UserslupinAppDataLocalProgramsPythonPython39libsite-packagesmysqlconnectorconversion.py", line 185, in to_mysql
raise TypeError("Python '{0}' cannot be converted to a "
TypeError: Python 'method' cannot be converted to a MySQL type
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UserslupinAppDataLocalProgramsPythonPython39libkinter\__init__.py", line 1884, in __call__
return self.func(*args)
File "Z:My FilesStudent My DocumentsA LevelComputingNEA
ea2.py", line 168, in <lambda>
submit = tk.Button(frame1, text="Submit information", command=lambda:infoget(question1.get,question2.get(),question3.get(),values.get()),width=18)
File "Z:My FilesStudent My DocumentsA LevelComputingNEA
ea2.py", line 179, in infoget
mycursor.execute(sql, statement)
File "C:UserslupinAppDataLocalProgramsPythonPython39libsite-packagesmysqlconnectorcursor.py", line 557, in execute
psub = _ParamSubstitutor(self._process_params(params))
File "C:UserslupinAppDataLocalProgramsPythonPython39libsite-packagesmysqlconnectorcursor.py", line 436, in _process_params
raise errors.ProgrammingError(
mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python 'method' cannot be converted to a MySQL type
I have no idea what created and/or caused this error. If anyone can help resove this or point me in the right direction to fix this I would be very grateful!
Thank you, Lupin