gpt4 book ai didi

python - 全屏 Python TKinter 或 wxPython 窗口,但所有窗口的 'stay at the bottom'?

转载 作者:太空狗 更新时间:2023-10-30 01:30:11 28 4
gpt4 key购买 nike

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

这主要是为了让笔记本电脑 child 安全。我希望 child (4 岁)能够访问某些选定的应用程序,即。 gcompris、childs play、tux math 等,但不是真正的其他应用程序和设置。诸如自定义桌面 + 启动器面板之类的东西,没有任何可破坏的东西,无法访问文件等。

我希望面板包含一些可以启动其他应用程序的按钮(使用 subprocess.call),但面板本身需要保留在从它启动的任何内容之下,或者为了让事情变得更容易,所以它保留在任何打开的全屏游戏之下,并且每个打开的窗口(即使面板获得焦点)。

Python tkinter 的全屏 overrideredirect(True) 将是完美的(带有密码保护的关闭按钮),如果不是因为它不允许其他应用程序出现在它上面,我不确定是否可以让它保留在一切的底部。

如果可能的话,知道如何改变这种行为,或者有任何其他工具可以让我在 python 或其他方式中做到这一点吗?

编辑:附加信息:

我几乎可以正常工作了,但另一个奇怪的行为是 overrideredirect(True)。我可以在开始时降低()该应用程序并且它没问题,但是当我使用 overrideredirect(True) 执行此操作时,该应用程序完全消失了。非全屏测试代码如下:

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) 行并按下按钮,应用程序仍会运行但将不再可见。

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

>>>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 对我的窗口做一些事情......炒作 :)

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

编辑。使用不同的工具 - wxPython 再看问题

这次我尝试使用简单的方法 - 使用 Boa Constructor。虽然窗口框架上的 app.lower() 在 Tkinter 上运行良好,但出于某种原因,我现在在使用 wxPython 时遇到了问题。在下面的代码中——按下按钮在框架上打开一个 gedit 窗口,2 秒后框架被带到顶部,再过 2 秒后它应该落到窗口堆栈的底部,但这不会发生,至少不在我的 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.:

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

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

现在我的想法用完了,可能我会按照建议坚持使用 guest 帐户。

最佳答案

这就是我在 pygame on windows 中设置窗口位置的方式。这样,它将覆盖所有其他窗口,如果将 -1 更改为 1,它将位于其他窗口后面,我只知道它在 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)

制作全屏窗口是通过以下方式完成的:

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

关于python - 全屏 Python TKinter 或 wxPython 窗口,但所有窗口的 'stay at the bottom'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8553418/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com