Reputation: 37
[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). 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.
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()
Upvotes: 1
Views: 474
Reputation: 142641
Your code works for me on Linux Mint 19.2 with Gnome if I remove
root.update_idletasks()
or if I use it after 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 = 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()
Upvotes: 3