2012-04-05 60 views
2

我對Python相當陌生。這裏有一個我從我們的MySQL服務器收集託管我們的服務檯門票的信息的腳本,並且當新的門票到達時將彈出消息框(使用EasyGUI的「msgbox()」函數)。Python - 彈出MsgBox後繼續執行代碼?

問題是,我希望我的程序在彈出窗口後繼續處理,無論用戶是否單擊「OK」或不是,即使這意味着消息框可能會彈出對方並必須被一個一;那對我來說很好。

我看着線程,要麼它不工作,要麼做了錯誤的事情,需要一個好的指導。這裏是我的代碼:

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() 
+1

有沒有在你的榜樣 – Intra 2012-04-05 17:13:24

+0

沒有穿線你需要的是一個非模態非模態(而不是模態)對話。大多數圖形軟件包都提供此選項,但快速瀏覽easyGUI文檔似乎並未表明可能性。 – jpm 2012-04-05 17:18:32

+0

@intra我嘗試了線程,它沒有工作,所以我把它拿出來了。 – armani 2012-04-05 18:01:50

回答

2

您可以使用Python GTK+

,提供使用

set_modal(False) 
+1

我一直遇到太多ImportErrors ...現在我只是花太多時間(這等於錢)在一些如此愚蠢和簡單的事情上。即使這是模態,我正在用os.system(「msg console(%s)%message」)解決。 – armani 2012-04-06 18:39:25

相關問題