from __future__ import annotations

import tkinter as tk


def is_maximized(window: tk.Tk) -> bool:
    try:
        if window.state() == "zoomed":
            return True
    except tk.TclError:
        pass
    try:
        return bool(int(window.attributes("-zoomed")))
    except (tk.TclError, TypeError, ValueError):
        return False


def maximize(window: tk.Tk) -> bool:
    try:
        window.state("zoomed")
        if is_maximized(window):
            return True
    except tk.TclError:
        pass
    try:
        window.attributes("-zoomed", True)
        return bool(int(window.attributes("-zoomed")))
    except (tk.TclError, TypeError, ValueError):
        return False
