如何在没有 overrideredirect 或属性的情况下在 linux LXDE 上使用 tkinter 删除标题栏? [英] How do I remove the title bar with tkinter on linux LXDE without overrideredirect or attributes?

查看:34
本文介绍了如何在没有 overrideredirect 或属性的情况下在 linux LXDE 上使用 tkinter 删除标题栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[我之前的帖子被关闭,说明它是重复的,但我仍然没有答案]

[my previous post was closed stating it was a duplicate but I still do not have an answer]

我正在尝试创建一个没有带有按钮的标题栏的窗口.这些按钮将打开/运行某些程序(打开网络浏览器、重新启动计算机等).我希望此窗口始终保留在屏幕上并且无法关闭(就像屏幕上带有按钮的信息亭一样).

I am trying to create a window without a title bar that has buttons on it. These buttons would open/run certain programs (open web browser, reboot computer, etc). I want this window to remain on the screen always and not able to be closed (like a kiosk with buttons on the screen).

在 Windows 上,我可以使用 overrideredirect(True) 和 attributes("-topmost", True) 使这项工作正常进行.但是,当我使用 LXDE 在树莓派上运行该程序时,它无法识别 overrideredirect(True).我尝试将 True 更改为 1,但仍然没有成功.我无法专门为 LXDE 找到任何关于此的信息.由于我的窗口管理器没有响应这个论点,这是不可能的吗?也许有另一种方法可以完成我正在尝试做的事情.

On windows, I am able to make this work fine with overrideredirect(True) and attributes("-topmost", True). However, when I run the program on a raspberry pi with LXDE, it doesn't recognize the overrideredirect(True). I have tried changing True to 1 and still no success. I am unable to find anything about this for LXDE specifically. Is it not possible since my window manager is not responding to this argument? Maybe there is another way to accomplish what I am trying to do.

我也尝试了 attributes('-type', 'splash')attributes('-type', 'dock') 没有成功.

I also tried the attributes('-type', 'splash') and attributes('-type', 'dock') without success.

import tkinter as tk
import webbrowser

root = tk.Tk()

#URL to open when Browser button
browser_url = 'http://www.google.com'

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack(fill=tk.BOTH, expand=1, pady=20)
        self.create_widgets()

    def create_widgets(self):           
        self.browser = tk.Button(self, height=2, width=10)
        self.browser["text"] = "Browser"
        self.browser["command"] = self.browser_go
        self.browser.pack(side="left", padx=25)

    def browser_go(self):
        webbrowser.open_new(browser_url)            

root.geometry('2160x100+0+0')       #Window size (x,y) and location (x,y)
root.resizable(False, False)        #Window not resizeable
root.update_idletasks()
root.overrideredirect(True)         #Prevent ability to close the windows
root.attributes("-topmost", True)   #Window on top always of other windows
app = Application(master=root)
app.mainloop()

推荐答案

如果我删除了,你的代码适用于 Linux Mint 19.2 和 Gnome

Your code works for me on Linux Mint 19.2 with Gnome if I remove

root.update_idletasks()

或者如果我在 root.overrideredirect(True)

也许它也适用于您的系统.

Maybe it will works also for your system.

import tkinter as tk
import webbrowser

root = tk.Tk()

#URL to open when Browser button
browser_url = 'http://www.google.com'

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack(fill=tk.BOTH, expand=1, pady=20)
        self.create_widgets()

    def create_widgets(self):           
        self.browser = tk.Button(self, height=2, width=10)
        self.browser["text"] = "Browser"
        self.browser["command"] = self.browser_go
        self.browser.pack(side="left", padx=25)

    def browser_go(self):
        webbrowser.open_new(browser_url)            

root.geometry('2160x100+0+0')       #Window size (x,y) and location (x,y)
root.resizable(False, False)        #Window not resizeable
root.overrideredirect(True)         #Prevent ability to close the windows

#root.update_idletasks() # has to be after root.overrideredirect(True)

root.attributes("-topmost", True)   #Window on top always of other windows
app = Application(master=root)
app.mainloop()

我什至不需要 root.resizable(False, False)root.attributes("-topmost", True)

root = tk.Tk()
root.geometry('2160x100+0+0')       #Window size (x,y) and location (x,y)
root.overrideredirect(True)         #Prevent ability to close the windows
app = Application(master=root)
app.mainloop()

这篇关于如何在没有 overrideredirect 或属性的情况下在 linux LXDE 上使用 tkinter 删除标题栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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