2009-12-17 165 views
2
#!/usr/bin/env python 
# Display window with toDisplayText and timeOut of the window. 

from Tkinter import * 

def showNotification(notificationTimeout, textToDisplay): 

    ## Create main window 
    root = Tk() 
    Button(root, text=textToDisplay, activebackground="white", bg="white", command=lambda: root.destroy()).pack(side=LEFT) 

    root.update_idletasks() 
    # Remove window decorations 
    root.overrideredirect(1) 

    timeOut = int(notificationTimeout*1000) # Convert to ms from s 

    ## Run appliction 
    root.after(timeOut,root.destroy) 
    root.mainloop() 

上面的代碼創建一個通知,帶有timout。但是,在Windows上 - 通知不會自動彈出超過所有其他當前窗口。你必須點擊殺死按鈕(文本),並在第一次集中它,之後根窗口將顯示在所有其他窗口之上。使tkinter窗口出現在所有其他窗口上

有沒有辦法使通知自動出現在所有其他窗口之上 - 在Windows上?

它似乎在linux上工作得很好(Ubuntu 9.10)。

回答

6

根據this message你應該可以在root.overridedirect(1)之後添加以下內容。這裏的一個快速測試表明它應該適合你。

root.wm_attributes("-topmost", 1) 
+0

我不認爲這適用於osx? –

+0

不知道......我沒有做太多的OSX。然而,剛剛在OSX 10.5.8上使用Python 2.6.5進行了測試,並得到一個錯誤'''_tkinter.TclError:錯誤的選項「-topmost」:必須是-modified或-titlepath'''。不管什麼意思。 –

+0

是的,我認爲這個技巧只適用於Windows?它在Linux上工作嗎? –

相關問題