Python - 继续代码执行后弹出 MsgBox?

2024-09-30 01:23:32 发布

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

我对Python相当陌生。我有一个脚本,它从托管帮助台问题的MySQL服务器收集信息,并在新问题到达时弹出一个消息框(使用EasyGUI的“msgbox()”函数)。在

问题是,我希望我的程序在弹出后继续处理,不管用户是否单击“确定”,即使这意味着消息框可能会不断弹出,必须逐个关闭;这对我来说没问题。在

我研究过线程,要么它不起作用,要么我做错了什么,需要一个好的指导。我的代码是:

import MySQLdb
import time
from easygui import *

# Connect
db = MySQLdb.connect(host="MySQL.MyDomain.com", user="user", passwd="pass", db="db")
cursor = db.cursor()

# Before-and-after arrays to compare; A change means a new ticket arrived
IDarray = ([0,0,0])
IDarray_prev = ([0,0,0])

# Compare the latest 3 tickets since more than 1 may arrive in my time interval
cursor.execute("SELECT id FROM Tickets ORDER BY id DESC limit 3;")
numrows = int(cursor.rowcount)
for x in range(0,numrows):
   row = cursor.fetchone()
   for num in row:
      IDarray_prev[x] = int(num)
cursor.close()
db.commit()

while 1:
   cursor = db.cursor()
   cursor.execute("SELECT id FROM Tickets ORDER BY id DESC limit 3;")

   numrows = int(cursor.rowcount)
   for x in range(0,numrows):
      row = cursor.fetchone()
      for num in row:
         IDarray[x] = int(num)

   if(IDarray != IDarray_prev): 
      cursor.execute("SELECT Subject FROM Tickets ORDER BY id DESC limit 1;")
      subject = cursor.fetchone()
      for line in subject:
         # -----------------------------------------
         # STACKOVERFLOW, HERE IS THE MSGBOX LINE!!!
         # -----------------------------------------
         msgbox("A new ticket has arrived:\n"+line)

   # My time interval -- Checks the database every 8 seconds:
   time.sleep(8)
   IDarray_prev = IDarray[:]
   cursor.close()
   db.commit()

Tags: inimportidforexecutedbtimeselect

热门问题