How to create a resizable Windows without title bar in Tkinter?

TkinterPythonGUI-Programming

To create a tkinter window without title bar, we can use overrideredirect(boolean) property which disables the navigation panel from the top of the tkinter window. However, it doesn’t allow the user to resize the window instantly.

If we are required to create a resizable window without the title bar programmatically, then we can use Sizegrip(parent) widget in Tkinter. The Sizegrip widget adds extendibility to the application that allows users to pull and resize the main window. To work with Sizegrip widget, we have to Bind the mouse buttons and a function that resizes the window whenever we pull the grip.

Example

# Import the required libraries
from tkinter import *
from tkinter import ttk

# Create an instance of tkinter frame or window
win=Tk()

# Set the size of the window
win.geometry("700x350")

# Remove the Title bar of the window
win.overrideredirect(True)

# Define a function for resizing the window
def moveMouseButton(e):
   x1=winfo_pointerx()
   y1=winfo_pointery()
   x0=winfo_rootx()
   y0=winfo_rooty()

   win.geometry("%s x %s" % ((x1-x0),(y1-y0)))

# Add a Label widget
label=Label(win,text="Grab the lower-right corner to resize the window")
label.pack(side="top", fill="both", expand=True)

# Add the gripper for resizing the window
grip=ttk.Sizegrip()
grip.place(relx=1.0, rely=1.0, anchor="se")
grip.lift(label)
grip.bind("<B1-Motion>", moveMouseButton)

win.mainloop()

If we run the above code, it will display a window without any title bar. We can resize this window by pulling the grip from the lower-right corner.

Output

raja
Published on 18-Jun-2021 13:35:26
Advertisements