Here is my approach to this, you can make use of the root.attributes()
method instead, you do not need to use root.overrideredirect()
in that case, because going full screen will automatically imply that, here is the modified code
from tkinter import *
root = Tk()
root.title('Кликер')
full_screen = 0
root.geometry('1920x1080')
root.attributes('-fullscreen',True)
def full_size(event):
global full_screen
if full_screen == 1:
root.attributes('-fullscreen',True)
full_screen = 0
else:
root.attributes('-fullscreen',False)
full_screen = 1
root.bind('<F11>', full_size)
root.mainloop()
As far as I know, the possible reason as to why the window closes on pressing alt-tab in your code could be based on the fact that overrideredirect()
does the following as stated here
Instruct the window manager to ignore this widget if BOOLEAN is given with 1.
Also as said here
You can use overrideredirect() and set its flag to True. This will disable your window to be closed by regular means as mentioed in the link above. By regular means, it is meant the X button and the Alt + F4 keystrokes combination.
Which basically indicates that when overrideredirect()
is used on your full screen sized window, the OS has no means to minimise it when you use alt-tab and hence closes it permanetly and cant be re-opened hence after. (Please feel free to correct me on this)
UPDATE
You can do this without using flags as well, refer to the code below
from tkinter import *
root = Tk()
root.title('Кликер')
root.geometry('1920x1080')
root.attributes('-fullscreen',True)
def full_size(event):
global full_screen
if root.attributes('-fullscreen'):
root.attributes('-fullscreen',False)
else:
root.attributes('-fullscreen',True)
root.bind('<F11>', full_size)
root.mainloop()