在所有其他窗口上显示一个tkinter窗口 [英] Make a tkinter window appear over all other windows

查看:457
本文介绍了在所有其他窗口上显示一个tkinter窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 #!/ usr / bin / env python 
#显示窗口的toDisplayText和timeOut窗口。




$ b def showNotification(notificationTimeout,textToDisplay):

##创建主窗口
root = Tk()
Button(root,text = textToDisplay,activebackground =white,bg =white,command = lambda:root.destroy())。pack(side = LEFT)

root .update_idletasks()
#删除窗口装饰
root.overrideredirect(1)

timeOut = int(notificationTimeout * 1000)#从s
$ b转换为ms $ b ##运行申请
root.after(timeOut,root.destroy)
root.mainloop()

上面的代码用timout创建一个通知。但是,在Windows上,通知不会自动弹出所有其他当前窗口。你必须点击杀死按钮(文本),并在第一次集中它,之后,根窗口将显示在所有其他窗口之上。



有没有办法让通知自动出现在所有其他窗口之上 - 在Windows上?



看来在linux上工作就好了(ubuntu 9.10)。根据 解决方案 .org / pipermail / python-win32 / 2006-May / 004678.htmlrel =noreferrer> this message 你应该可以在 root.overridedirect(1)

  root.wm_attributes( -  topmost,1)


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

The above code creates a notification, with a timout. However on windows - the notification does not automatically pop up above all other present windows automatically. One has to click on the kill button (the text), and focus it the first time, after which the root window will be displayed above all other windows.

Is there a way to make the notification automatically appear above all other windows - on windows?

It seems to work on linux just fine (ubuntu 9.10).

解决方案

According to this message you should be able to add the following after root.overridedirect(1). A quick test here suggests it should work for you.

root.wm_attributes("-topmost", 1)

这篇关于在所有其他窗口上显示一个tkinter窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆