全屏Python TKinter或wxPython窗口,但是“停留在所有窗口的底部"吗? [英] Fullscreen Python TKinter or wxPython window, but 'stay at the bottom' of all windows?

查看:291
本文介绍了全屏Python TKinter或wxPython窗口,但是“停留在所有窗口的底部"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个全屏面板,以可视方式阻止访问屏幕上的所有内容(Ubuntu(11.10)中的桌面,菜单,Unity面板等),但保持在其他应用程序打开的窗口下方.

I want to create a fullscreen panel that visually blocks access to everything on the screen (desktop, menu, Unity Panel, etc in Ubuntu (11.10)), but stays below other applications' opened windows.

这主要是为了使便携式计算机成为孩子的证据.我希望孩子(4岁)可以访问某些选定的应用程序,即. gcompris,儿童游戏,无尾礼服数学等,但对其他应用程序和设置却并非如此.诸如自定义桌面+启动器面板之类的东西,没有任何损坏,无法访问文件等.

This is mainly to make the laptop child proof. I want the kid (4 years old) to have access to some selected apps ie. gcompris, childs play, tux math, etc. but not really to other apps and settings. Something like custom desktop + launcher panel without anything to break, no access to files, etc.

我希望面板包含一些可以启动其他应用程序的按钮(使用subprocess.call),但是面板本身需要停留在从其启动的任何内容下,或者使其变得更容易,以便使其停留在任何已打开的全屏游戏和每个打开的窗口(即使面板聚焦时).

I want the panel to contain some buttons that would start other applications (using subprocess.call) but the panel itself needs to stay under anything that's launched from it or to make things easier just so it stays under any opened fullscreen games and every opened window (even when the panel takes focus).

Python tkinter的全屏overrideredirect(True)将是完美的(带有密码保护的关闭按钮),如果不是它不允许其他应用程序出现在它上面并且我不确定是否可以保留它的话在所有内容的底部.

Python tkinter's fullscreen overrideredirect(True) would be perfect (with a password protected close button) if not the fact that it does not allow other applications to appear over it and I'm not sure if it is possible to make it stay at the bottom of everything.

有什么想法,如果可能的话,如何改变这种行为,或者任何其他使我能够以python或其他方式执行此操作的工具?

Any idea how to change this behavior if possible, or any other tools that would enable me to do this in python or otherwise?

其他信息:

我几乎可以正常工作了,但是还有另一个奇怪的行为,那就是overrideredirect(True).我可以在启动时降低()应用程序的正常性,但是当我使用overrideredirect(True)进行操作时,该应用程序将完全消失.非全屏测试代码如下:

I have got it nearly working but another strange behaviour with overrideredirect(True). I could lower() the app at the start and its ok, but when I do it with the overrideredirect(True) the app disappears completely. Non-fullscreen testing code below:

from tkinter import *

def btn1_click():app.quit();app.destroy()
def btn2_click():app.lower()    
def handler():
    if tkinter.messagebox.askyesno("Quit?", "Are you sure you want to quit?"):
        app.quit();app.destroy()

app = Tk()
app.title("Testing...")
app.geometry('300x100+200+100')
#app.overrideredirect(True) 
#app.lower()

b1 = Button(app, text = "Exit!", width = 10, command = btn1_click);b1.pack()
b2 = Button(app, text = "Lower", width = 10, command = btn2_click);b2.pack()
app.protocol("WM_DELETE_WINDOW", handler)
app.mainloop()

按原样运行时,它将打开新窗口,然后按降低"按钮将其发送回背面,但是如果取消注释app.overrideredirect(True)行并按按钮,则该应用程序仍将运行但将不再可见.

when you run it as it is it will open new window and pressing the 'Lower' button will send it to the back, but if you uncomment the app.overrideredirect(True) line and press the button the app will still run but will no longer be visible.

编辑... 好吧,我想我明白了:

Edit... Ok, I think I get it:

>>>help(tkinter)
...
     |  overrideredirect = wm_overrideredirect(self, boolean=None)
     |      Instruct the window manager to ignore this widget
     |      if BOOLEAN is given with 1. Return the current value if None
     |      is given.
...

因此,首先,我要让窗口管理器忽略我的窗口,但是后来我仍然希望wm对我的窗口做一些事情……谦卑:)

So, first I am asking the window manager to ignore my window, but later I still want the wm to do something to my window... hypcracy :)

还有其他方法可以在不要求wm忽略窗户的情况下剥离窗户装饰吗?

Any other ways to strip window decoration without asking the wm to ignore the window?

编辑.另一种工具-wxPython

Edit. Another look at the problem with a different tool - wxPython

这一次,我尝试使用简单的方法-使用Boa构造函数.虽然窗口框架上的app.lower()在Tkinter上运行良好,但由于某种原因,我现在对wxPython遇到了问题.在下面的代码中-按下按钮会在框架上打开一个gedit窗口,然后在2秒钟后将框架移到顶部,再过2秒钟应将其降至窗口堆栈的底部,但这至少不会发生不在我的Ubuntu上.

This time I'm trying it the easy way - using the Boa Constructor. While app.lower() on a windowed Frame worked fine with Tkinter, for some reason I have a problem with wxPython now. In the code below - pressing the button opens a gedit window over the Frame, than 2 seconds later frame is brought to the top and another 2 seconds later it should fall to the bottom of the window stack, but that does not happen, at least not on my Ubuntu.

def OnButton3Button(self, event):
    subprocess.call("gedit") #opens gedit above the Frame
    time.sleep(2) #waits for 2 seconds
    self.Raise() #brings the Frame to the top
    time.sleep(2) #waits for another 2 seconds
    self.Lower() #should Lower the Frame to the bottom, but it doesn't

如果我可以使Lower()以某种方式工作,则可以通过ie.

if I could make the Lower() work somehow it would be easily done by ie.:

def OnFrame1Activate(self, event):
    self.ShowFullScreen(True)

def OnFrame1EnterWindow(self, event):
    self.Lower()

现在我用尽了所有想法,可能我只会按照建议使用来宾帐户".

Now I run out of ideas, probably I will just stick to the Guest Account as suggested.

推荐答案

这是我在pygame中在Windows上设置窗口位置的方法. 这样,它将覆盖所有其他窗口,如果将-1更改为1,它将位于其他窗口后面,我只知道它可以在窗口中工作.

This is how I set the window position in pygame on windows. With this, it will cover all other windows, if you change the -1 to a 1 it will be behind other windows, I only know it works in windows.

import pygame, time, datetime, ctypes
from pygame.locals import *
from ctypes import windll

pygame.init()
set_window_pos = windll.user32.SetWindowPos
monitorsize = ctypes.windll.user32
resolution_X = monitorsize.GetSystemMetrics(0)
resolution_Y = monitorsize.GetSystemMetrics(1)

screen = pygame.display.set_mode((255, 242), pygame.NOFRAME)
set_window_pos(pygame.display.get_wm_info()['window'], -1, (resolution_X - 255), 50, 0, 0, 0x0001)

使窗口FULLSCREEN完成:

Making a window FULLSCREEN is done with:

screen = pygame.display.set_mode((800, 350), FULLSCREEN) # this works in linux

这篇关于全屏Python TKinter或wxPython窗口,但是“停留在所有窗口的底部"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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