Reputation: 59
It will not allow me to access my hints from my database, an error comes up.
Code:
def do_question(self):
self.func1()
#myGlobal + 1
if myGlobal >5:
import MathsvadersReal
SQL = 'SELECT * FROM tblQuestion'
cursor = Databaseconnector.SELECT(SQL)
rows = cursor.fetchall()
random_row = random.choice(rows)
print random_row.QuestionID, random_row.Question, random_row.Hint, random_row.A1, random_row.A2, random_row.A3, random_row.A4, random_row.CorrectAnswer
# create welcome label
self.label1 = Tkinter.Label(self, bg ='yellow', text = (random_row.Question))
self.label1.grid(row = 0, column = 6, columnspan = 2, sticky = 'E')
self.label111 = Tkinter.Label(self, bg ='red', text = (random_row.QuestionID))
self.label111.grid(row = 0, column = 1, columnspan = 4, sticky = 'W')
Hint Code:
def homepage_link(self):
SQL = 'SELECT Hint FROM tblQuestion WHERE QuestionID = %s' % self.label111
cursor = Databaseconnector.SELECT(SQL)
rows = cursor.fetchall()
tkMessageBox.showinfo("Hint", rows[0]['Hint'])
ERROR:
IndexError: list index out of range
Upvotes: 0
Views: 773
Reputation: 20679
You are passing the string representation of the widget instead of the text
option. The first line of homepage_link
should be:
SQL = 'SELECT Hint FROM tblQuestion WHERE QuestionID = %s' % self.label111['text']
Upvotes: 1