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.
Updated Solution :This is the final code that seems to work without a problem.
def toggle_fullscreen(event):
if (root.attributes('-fullscreen')):
root.attributes('-fullscreen', False)
else:
root.attributes('-fullscreen', True)
root.bind("<F11>", toggle_fullscreen)
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)