Tkinter: windows without a title, but resizable

What I know, if I want to create a window without a title, I can write

root = Tk() ........ root.overrideredirect(1) 

But I would also like the window to change. Is there any solution?

(FYI: I work on a Windows machine, although I'm not sure if it really matters. It would be ideal if there is an OS independent solution, but I'm glad if there is a Windows solution first.)

+7
source share
1 answer

The problem is that the window is volatile, but when you enable overrideredirect , you lose any title or edge that you can grab to resize the window. The only solution is to resize. You can add your own borders or add mouse bindings that work when the mouse is near the edge.

This answer shows how to move such a window: Python / Tkinter: the mouse drags the window without borders, for example. overridedirect (1)

Here is a quick example illustrating resizing. It has hardly been tested on OSX, but should work on any platform. It uses python2, although it should work with python3 simply by modifying the import statements.

 import Tkinter as tk import ttk class Example(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.floater = FloatingWindow(self) class FloatingWindow(tk.Toplevel): def __init__(self, *args, **kwargs): tk.Toplevel.__init__(self, *args, **kwargs) self.overrideredirect(True) self.wm_geometry("400x400") self.label = tk.Label(self, text="Grab the lower-right corner to resize") self.label.pack(side="top", fill="both", expand=True) self.grip = ttk.Sizegrip(self) self.grip.place(relx=1.0, rely=1.0, anchor="se") self.grip.lift(self.label) self.grip.bind("<B1-Motion>", self.OnMotion) def OnMotion(self, event): x1 = self.winfo_pointerx() y1 = self.winfo_pointery() x0 = self.winfo_rootx() y0 = self.winfo_rooty() self.geometry("%sx%s" % ((x1-x0),(y1-y0))) return app=Example() app.mainloop() 
+9
source

All Articles