Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How would I make a command check whether a window has the attributes of Fullscreen as True or False

So I am trying to make some simple buttons that allow the user to minimize and maximize the app window and I am trying to make it so a button can be pressed to set the window as fullscreen and when in fullscreen it can be pressed again to set the window in windowed mode. I have tried to set the window attributes for fullscreen as functions to make an if else statement but all that would happen is that the app would go fullscreen and if I press the button again it would only minimize for a second before going back to fullscreen.

import tkinter.messagebox
from tkinter import *
import customtkinter
from PIL import Image, ImageTk
import sys

customtkinter.set_appearance_mode("dark") # Modes: System(default), Light, Dark
customtkinter.set_default_color_theme("dark-blue") #modes: blue, dark-blue, green

window = customtkinter.CTk()
window.title("To-Do List")
#window.overrideredirect(1)

#fullscreen
def Fulwin():
    window.attributes('-fullscreen', True)
#windowed mode
def Nonwin():
    window.attributes('-fullscreen', False)


## Minimize, maximize, and exit button

def Ifullscreen():
    if Fulwin:
        Nonwin
    else: Fulwin

#Maxamize/Minimize Button

maximize_image = ImageTk.PhotoImage(Image.open("GUI/Maximize.png"))
maximize_button = customtkinter.CTkButton(master=window, image=maximize_image, text="",command=Ifullscreen,
                                          width=30, height=30, fg_color='#1a1a1a', hover_color='#1a1a1a')
maximize_button.pack(padx=5,pady=5)
maximize_button.place(x=1450,y=10)

#Hide Button
def Minsize():
    window.attributes('-fullscreen',False)
minimize_image = ImageTk.PhotoImage(Image.open("GUI/minimize.png"))
minimize_button = customtkinter.CTkButton(master=window, image=minimize_image, text="", command=Minsize,
                                          width=30, height=30, fg_color='#1a1a1a', hover_color='#1a1a1a')
minimize_button.pack(padx=5,pady=5)
minimize_button.place(x=1400,y=10)

#Exit Button
def Exsize():
    sys.exit()
exit_image = ImageTk.PhotoImage(Image.open("GUI/exit.png"))
exit_button = customtkinter.CTkButton(master=window, image=exit_image, text="", command=Exsize,
                                      width=30, height=30, fg_color='#1a1a1a', hover_color='#1a1a1a')
exit_button.pack(padx=5,pady=5)
exit_button.place(x=1500,y=10)

window.mainloop()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Side note: For future questions could you make what part you are having problems with more explicit (e.g. Putting a comment before what you are asking and keeping your code snippets to a small size).

The Nonwin and Fulwin functions can just be replaced to one function: e.g.

def Ifullscreen():
    window.attributes("-fullscreen", not window.attributes("-fullscreen"))

And then just delete Fulwin and Nonwin functions.

If you wish to keep similar function names (I would not recommend this) here you go:

#fullscreen
def Fulwin():
    window.attributes('-fullscreen', True)
#windowed mode
def Nonwin():
    window.attributes('-fullscreen', False)


## Minimize, maximize, and exit button

def Ifullscreen():
    if window.attributes('-fullscreen'):
        Nonwin()
    else:
        Fulwin()

I’m pretty sure this is what you were looking for.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading