A simplification of @patthoyts's answer:
# Partially taken from: https://stackoverflow.com/a/2400467/11106801
from ctypes.wintypes import BOOL, HWND, LONG
import tkinter as tk
import ctypes
# Defining functions
GetWindowLongPtrW = ctypes.windll.user32.GetWindowLongPtrW
SetWindowLongPtrW = ctypes.windll.user32.SetWindowLongPtrW
def get_handle(root) -> int:
root.update_idletasks()
# This gets the window's parent same as `ctypes.windll.user32.GetParent`
return GetWindowLongPtrW(root.winfo_id(), GWLP_HWNDPARENT)
# Constants
GWL_STYLE = -16
GWLP_HWNDPARENT = -8
WS_CAPTION = 0x00C00000
WS_THICKFRAME = 0x00040000
if __name__ == "__main__":
root = tk.Tk()
hwnd:int = get_handle(root)
style:int = GetWindowLongPtrW(hwnd, GWL_STYLE)
style &= ~(WS_CAPTION | WS_THICKFRAME)
SetWindowLongPtrW(hwnd, GWL_STYLE, style)
The style &= ~(WS_CAPTION | WS_THICKFRAME)
just removes the title bar of the window. For more info read Microsoft's documentation.
Not really needed but to make it safer use this to define the functions:
# Defining types
INT = ctypes.c_int
LONG_PTR = ctypes.c_long
def _errcheck_not_zero(value, func, args):
if value == 0:
raise ctypes.WinError()
return args
# Defining functions
GetWindowLongPtrW = ctypes.windll.user32.GetWindowLongPtrW
GetWindowLongPtrW.argtypes = (HWND, INT)
GetWindowLongPtrW.restype = LONG_PTR
GetWindowLongPtrW.errcheck = _errcheck_not_zero
SetWindowLongPtrW = ctypes.windll.user32.SetWindowLongPtrW
SetWindowLongPtrW.argtypes = (HWND, INT, LONG_PTR)
SetWindowLongPtrW.restype = LONG_PTR
SetWindowLongPtrW.errcheck = _errcheck_not_zero
I know the question specifically says it's about Windows but for Linux, this should work.