1

I ran into a problem. If you open the tkitner window in full screen, and then press Alt+Tab, then Tkinter will collapse, without the possibility of opening again

from tkinter import *

root = Tk()

root.title('Кликер')
full_screen = 0
root.geometry('1920x1080')

full_screen = 0


def full_size(event):
    global full_screen
    if full_screen == 1:
        root.overrideredirect(False)
        full_screen = 0
    else:
        root.overrideredirect(True)
        full_screen = 1


root.bind('<F11>', full_size)

root.mainloop()
zefercka
  • 27
  • 6

1 Answers1

1

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()
astqx
  • 2,058
  • 1
  • 10
  • 21