[英]i am getting this error : " UnboundLocalError: local variable 'Requesting_books' referenced before assignment "
[英]I am getting an error: “UnboundLocalError: local variable 'text_to_print' referenced before assignment”
def search():
def back():
searchwindow.destroy()
def submit():
inputID = ID.get()
if inputID == "":
messagebox.showerror("Error", "Please Enter An ID")
elif len(inputID) != 6:
messagebox.showerror("Error", "ID Must Be 6 Characters Long")
else:
cursor.execute(("SELECT * FROM tblRoomAllocation WHERE roomID = ?"), (inputID,))
records = cursor.fetchall()
for record in records:
text_to_print = str(record[0]) + " | " + str(record[1]) + " | " + str(record[2]) + " | " + str(record[3]) + " | " + str(record[4])
messagebox.showinfo("Search Results", text_to_print)
我試圖將“text_to_print”設為全局,但它仍然給我同樣的錯誤。 我只是這方面的初學者,所以請幫忙。 感謝您的任何幫助。
將最后一行放在else中:
for record in records:
text_to_print = str(record[0]) + " | " + str(record[1]) + " | " + str(record[2]) + " | " + str(record[3]) + " | " + str(record[4])
if records:
messagebox.showinfo("Search Results", text_to_print)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.