数据库信息更改时更新Tkinter显示?

2024-09-28 22:28:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在为一个大学项目与树莓派,其中一些信息从表上显示通过Tkinter。在

程序在第一次启动时查询数据库中的区域活动,并设置Tkinter标签以显示其中一列中的某些数据(如果为真)。在

但是,如果我启动应用程序,并且找不到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 = ''

根据结果显示标签的代码

^{pr2}$

如果用户随后登录到相关应用程序并更新其区域以激活,则必须重新启动程序才能使更改生效。是否可以定期重新运行查询,并在变量更新时动态更改标签?如果是这样,这是如何实现的?在


Tags: id标签cursorresultsrowuseruseremailuserpassword