gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 13:00:46 25 4
gpt4 key购买 nike

我是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 - Python-弹出MsgBox之后继续执行代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10032879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com