简体   繁体   English

如何在没有覆盖重定向或属性的情况下在 linux LXDE 上使用 tkinter 删除标题栏?

[英]How do I remove the title bar with tkinter on linux LXDE without overrideredirect or attributes?

[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).我希望此窗口始终保留在屏幕上并且无法关闭(就像屏幕上带有按钮的信息亭)。

On windows, I am able to make this work fine with overrideredirect(True) and attributes("-topmost", True).在 Windows 上,我可以使用 overrideredirect(True) 和 attributes("-topmost", True) 使这项工作正常进行。 However, when I run the program on a raspberry pi with LXDE, it doesn't recognize the overrideredirect(True).但是,当我使用 LXDE 在树莓派上运行该程序时,它无法识别 overrideredirect(True)。 I have tried changing True to 1 and still no success.我尝试将 True 更改为 1,但仍然没有成功。 I am unable to find anything about this for LXDE specifically.我无法专门为 LXDE 找到任何关于此的信息。 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.也许有另一种方法可以完成我正在尝试做的事情。

I also tried the attributes('-type', 'splash') and attributes('-type', 'dock') without success.我也尝试了attributes('-type', 'splash')attributes('-type', 'dock')没有成功。

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()

Your code works for me on Linux Mint 19.2 with Gnome if I remove如果我删除,您的代码在带有 Gnome 的 Linux Mint 19.2 上对我有用

root.update_idletasks()

or if I use it after root.overrideredirect(True)或者如果我在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()

I don't need even root.resizable(False, False) and root.attributes("-topmost", True)我什至不需要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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM