如何在没有 overrideredirect 或属性的情况下使用 linux LXDE 上的 tkinter 删除标题栏?
How do I remove the title bar with tkinter on linux LXDE without overrideredirect or attributes?
[我之前的 post 已关闭,说明它是重复的,但我仍然没有答案]
我正在尝试创建一个 window 没有带有按钮的标题栏。这些按钮会 open/run 某些程序(打开网络浏览器、重启计算机等)。我希望此 window 始终保留在屏幕上并且无法关闭(就像屏幕上带有按钮的信息亭)。
在 windows,我可以使用 overrideredirect(True) 和 attributes("-topmost", True) 使这项工作正常进行。但是,当我使用 LXDE 运行 raspberry pi 上的程序时,它无法识别 overrideredirect(True)。我尝试将 True 更改为 1 但仍然没有成功。我找不到专门针对 LXDE 的任何信息。我的 window 经理没有回应这个论点,这不可能吗?也许还有另一种方法可以完成我想做的事情。
我也尝试了 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()
如果我删除
,您的代码适用于 Linux Mint 19.2 with Gnome
root.update_idletasks()
或者如果我在 root.overrideredirect(True)
之后使用它
也许它也适用于您的系统。
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()
[我之前的 post 已关闭,说明它是重复的,但我仍然没有答案]
我正在尝试创建一个 window 没有带有按钮的标题栏。这些按钮会 open/run 某些程序(打开网络浏览器、重启计算机等)。我希望此 window 始终保留在屏幕上并且无法关闭(就像屏幕上带有按钮的信息亭)。
在 windows,我可以使用 overrideredirect(True) 和 attributes("-topmost", True) 使这项工作正常进行。但是,当我使用 LXDE 运行 raspberry pi 上的程序时,它无法识别 overrideredirect(True)。我尝试将 True 更改为 1 但仍然没有成功。我找不到专门针对 LXDE 的任何信息。我的 window 经理没有回应这个论点,这不可能吗?也许还有另一种方法可以完成我想做的事情。
我也尝试了 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()
如果我删除
,您的代码适用于 Linux Mint 19.2 with Gnomeroot.update_idletasks()
或者如果我在 root.overrideredirect(True)
也许它也适用于您的系统。
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()