3
#!/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()

上記のコードは、タイムアウト付きの通知を作成します。ただし、ウィンドウでは、通知は他のすべての現在のウィンドウの上に自動的にポップアップしません。kill ボタン (テキスト) をクリックして、最初にフォーカスする必要があります。その後、ルート ウィンドウが他のすべてのウィンドウの上に表示されます。

ウィンドウ上で、通知を他のすべてのウィンドウの上に自動的に表示する方法はありますか?

Linuxで問題なく動作するようです(ubuntu 9.10)。

4

1 に答える 1

9

このメッセージによると、 の後に次を追加できるはずですroot.overridedirect(1)。ここでの簡単なテストは、それがうまくいくことを示唆しています。

root.wm_attributes("-topmost", 1)
于 2009-12-17T01:45:37.367 に答える