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

标签 python multithreading user-interface

我对 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()

最佳答案

您可以使用Python GTK+

它提供非模态使用

set_modal(False)

关于Python - 弹出MsgBox后继续执行代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10032879/

相关文章:

java - 使用Java在循环内并行执行方法

c++ - Qt:从类 MainWindow 访问函数:其他文件中的公共(public) QMainWindow

python - 单击按钮时打开一个新窗口 || PyQt5

java - 将 JPanel 大小设置为不大于其包含的元素

python - 在 Python 中列出问题

Python美汤选择文本

python - 在 Ubuntu 上导入 selenium 时出错

multithreading - OpenMP 了解关键构造中的死锁

python - 正则表达式 python : match multi-line float values between brackets

java - 迭代值时的 HashMap 线程安全