Is it possible to place widgets off window?
Question:
My question is simple – is it possible to place widgets out of bounds?
For example, I want a button to be not on tkinter.Tk
, but it will be somewhere else like in the center of monitor.
Answers:
tkinter.Tk
are only can place within bounds of a parent widget. For this you can need to create transparent tkinter.Toplevel
, then place in the needed location using method called geometry
.
import tkinter as tk
source = tk.Tk()
top = tk.Toplevel(source)
top.attributes('-alpha', 0.0)
width = source.winfo_screenwidth()
height = source.winfo_screenheight()
buttonsize = 50
x = (width - buttonsize) // 2
y = (height - buttonsize) // 2
top.geometry(f"{buttonsize}x{buttonsize}+{x}+{y}")
button = tk.Button(top, text="Click me!")
button.pack(fill=tk.BOTH, expand=True)
source.mainloop()
My question is simple – is it possible to place widgets out of bounds?
For example, I want a button to be not on tkinter.Tk
, but it will be somewhere else like in the center of monitor.
tkinter.Tk
are only can place within bounds of a parent widget. For this you can need to create transparent tkinter.Toplevel
, then place in the needed location using method called geometry
.
import tkinter as tk
source = tk.Tk()
top = tk.Toplevel(source)
top.attributes('-alpha', 0.0)
width = source.winfo_screenwidth()
height = source.winfo_screenheight()
buttonsize = 50
x = (width - buttonsize) // 2
y = (height - buttonsize) // 2
top.geometry(f"{buttonsize}x{buttonsize}+{x}+{y}")
button = tk.Button(top, text="Click me!")
button.pack(fill=tk.BOTH, expand=True)
source.mainloop()