user10135989
user10135989

Reputation:

How to toggle fullscreen mode?

I want my application to toggle fullscreen every time you click on the menu item. So if you click once, it becomes fullscreen, if you click again, it becomes normal again. I tried the following but after I clicked it again, it wouldn't switch.

def Fullscreen(self):
        self.fullscreen = False
        if not self.fullscreen:
            self.root.wm_attributes("-fullscreen", True)
        else:
            self.root.wm_attributes("-fullscreen", False)

Upvotes: 1

Views: 1189

Answers (1)

Mike - SMT
Mike - SMT

Reputation: 15226

You are missing a key part here. Nothing changes full screen back to True.

Here is a simple example of what you could do to toggle full screen.

import tkinter as tk


class App(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        tk.Button(self, text="Toggle Fullscreen", command=self.fullscreen_toggle).pack()
        self.fullscreen = False

    def fullscreen_toggle(self):
        if self.fullscreen == False:
            self.wm_attributes("-fullscreen", True)
            self.fullscreen = True
        else:
            self.wm_attributes("-fullscreen", False)
            self.fullscreen = False

app = App()
app.mainloop()

Upvotes: 4

Related Questions