我目前正在为一个带有覆盆子pi的大学项目工作,其中表格中的一些信息通过Tkinter显示。
程序在首次启动时查询数据库中的AreaActive,并设置Tkinter标签以显示其中一个列的某些数据(如果为true)。
但是,如果我启动应用程序并且未找到ActiveActive,则显示“找不到”可以在下面找到用于查询数据库的代码:
#Creating the cursor
cursor = db.cursor()
#search the database to to look for active area
sql = "SELECT * From User Where AreaActive = '%s'" % ('Yes')
try:
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
user_ID = row[0]
UserEmail = row[1]
UserPassword = row[2]
AreaActive = row[3]
NoteHeading = row[4]
NoteContent = row[5]
PubNoteHeading = row[6]
PubNoteContent = row[7]
TextSize = row[8]
Calapi = row[9]
print "user_ID=%d, UserEmail=%s, UserPassword=%s, AreaActive=%s, NoteHeading=%s, NoteContent=%s, PubNoteHeading=%s, PubNoteContent=%s, TextSize=%d, Calapi=%s" % \
(user_ID, UserEmail, UserPassword, AreaActive, NoteHeading, NoteContent, PubNoteHeading, PubNoteContent, TextSize, Calapi)
#error if no results found
except:
NoteHeading = 'None found'
NoteContent = 'None found'
TextSize = 22
Calapi = ''
基于结果显示标签的代码
self.notehead = Label(self, font=('Helvetica', medium_text_size), fg="white", wraplength=400, bg="black", text= NoteHeading)
self.notehead.pack(side=TOP, anchor=E)
self.notebody = Label(self, font=('Helvetica', TextSize),justify=RIGHT, fg="white", wraplength=400, bg="black", text= NoteContent)
self.notebody.pack(side=TOP, anchor=E)
如果用户随后登录到随播应用程序并将其区域更新为活动状态,则必须重新启动该程序才能使更改生效。是否可以定期重新运行查询并在变量更新时动态更改标签?如果是这样,这是如何实现的?