我想根据 mysqld 值检查用户对输入框小部件的输入,并在消息框中发出一条消息,说明他的答案是正确还是错误。一个例子可以是包含姓名和电话号码的数据库;如果用户输入给定名称的正确电话号码,则消息框会显示“您是对的”。否则“你错了”。姓名和电话号码在 mysqld 数据库中。因此,用户只能在其中一个输入框中看到姓名,而另一个输入框将是空的,供他输入电话号码。你能帮我么。
# prepare a cursor object using cursor() method
cursor = db.cursor()
# Execute the SQL command
cursor.execute("SELECT * FROM PHONES")
# Fetch all the rows in a list of lists
row0 = cursor.fetchone()[0]
row1 = cursor.fetchone()[1]
row2 = cursor.fetchone()[2]
#checking the values in a single row
if row1 == nameVar.get() and row2 == phoneVar.get():
tkMessageBox.showinfo("MCPHS Alpha Brand & Generic","You are right.")
elif row1 != nameVar.get() and row2 != phoneVar.get():
tkMessageBox.showerror("Check answer","Wrong answer")
else:
tkMessageBox.showerror("Check answer","Enter an answer")
# disconnect from server
db.close()
然后我会调用这样的方法
b7 = Button(frame2,text="Check Answer",command=checkAnswer)