Buğra Coşkun Buğra Coşkun - 3 months ago 20
Python Question

How to check if window is on Fullscreen in Tkinter?

I made F11 toggle fullscreen on. But how can I make it so that F11 can both toggle fullscreen on and off ?

I tried to make an [if] statement so it will turn it off if the window was previously toggled to fullscreen but I couldn't find a way to check if the window was already toggled or not.

Any help is appreciated, thank you.

Answer

This is the method I mentioned in my comment above:

from tkinter import *
root = Tk()

root.focus_set()

var = 0

def f(event):
    global var
    if var == 0:
        root.attributes("-fullscreen", True)
        var = 1
    else:
        root.attributes("-fullscreen", False)
        var = 0

root.bind("<F11>", f)
Comments