[我之前的帖子已关闭,表示它是重复的,但我仍然没有答案]
我正在尝试创建一个没有标题栏但带有按钮的窗口。这些按钮将打开/运行某些程序(打开网络浏览器、重新启动计算机等)。我希望此窗口始终保留在屏幕上并且无法关闭(就像屏幕上带有按钮的信息亭)。
在 Windows 上,我可以使用 overrideredirect(True) 和 attribute("-topmost", True) 使这项工作正常进行。但是,当我使用 LXDE 在树莓派上运行该程序时,它无法识别 overrideredirect(True)。我尝试将 True 更改为 1 但仍然没有成功。我找不到专门针对 LXDE 的任何信息。因为我的窗口管理器没有响应这个参数,这是不可能的吗?也许还有另一种方法来完成我想做的事情。
我还尝试了 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()
最佳答案
如果我删除,您的代码可以在带有 Gnome 的 Linux Mint 19.2 上运行
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.ressized(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()
关于python - 如何在 linux LXDE 上使用 tkinter 删除标题栏而不使用 overrideredirect 或属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59278333/