There is a good way to does it using .bind(), so let's get started!
As we know, we can maximize the window using the command .state('zoomed').
root.state('zoomed')
And we can get whatever window event by .bind("<Configure>", my_function)
So we can create create a simple function that catches a maximize window event, not necessarily a event by click, but it works.
Here's an example:
import tkinter
def window_event(event):
if root.state() == 'zoomed':
print("My window is maximized")
if __name__ == '__main__':
root = tkinter.Tk()
root.title("Maximized")
root.bind("<Configure>", window_event)
root.mainloop()
EDIT 1: New functionality
import tkinter
def window_event(event):
if root.state() == 'zoomed':
print("My window is maximized")
#GET A NORMAL WINDOW EVENT
#You can easily do this by a conditional statement, but remember if you even move the window position,
#this conditional statement will be true, because move the window is a window event
if root.state() == 'normal':
print("My window is normal")
if __name__ == '__main__':
root = tkinter.Tk()
root.title("Window")
root.geometry("620x480")
root.bind("<Configure>", window_event)
root.mainloop()
EDIT 2: New functionality
import tkinter
count = 0
def window_event(event):
global count
if root.state() == 'zoomed':
print("My window is maximized")
count = 0
if root.state() == 'normal' and count < 1:
print("My window is normal")
count +=1
if __name__ == '__main__':
root = tkinter.Tk()
root.title("Window")
root.geometry("620x480")
root.bind("<Configure>", window_event)
root.mainloop()
Take a look at this links, they are another way to work with Python GUI: