Open In App

How to Create Full Screen Window in Tkinter?

Last Updated : 13 Apr, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite: Tkinter

There are two ways to create a full screen window in tkinter using standard python library for creating GUI applications.

Method 1: Using attributes() function

Syntax:

window_name.attributes('-fullscreen',True)

We will set the parameter ‘-fullscreen’ of attributes() to True for setting size of our window to fullscreen and to False otherwise. 

Approach:

  • Importing tkinter package
  • Creating a tkinter window with name window
  • Setting the window attribute fullscreen as True
  • Giving title to the window, here ‘Geeks For Geeks’
  • Creating a label with text ‘Hello Tkinter’ (just for display to the user here)
  • Placing the label widget using pack()
  • Closing the endless loop of windows by calling mainloop()

Disadvantage:

We get an output tkinter WINDOW with no toolbar. This disadvantage is covered by the next method.

Program

Python3




# importing tkinter for gui
import tkinter as tk
 
# creating window
window = tk.Tk()
 
# setting attribute
window.attributes('-fullscreen', True)
window.title("Geeks For Geeks")
 
# creating text label to display on window screen
label = tk.Label(window, text="Hello Tkinter!")
label.pack()
 
window.mainloop()


Output:

Method 2: Using geometry() function

We get an output tkinter window with the toolbar above along with the title of window. 

Syntax:  

     width= window_name.winfo_screenwidth()               
     height= window_name.winfo_screenheight()               
     window_name.geometry("%dx%d" % (width, height))

We can set the parameter of geometry() same as the width*height of the screen of our original window to get our full screen tkinter window without making the toolbar invisible. We can get the width and height of our desktop screen by using winfo_screenwidth() and winfo_screenheight() functions respectively. 

Approach:

  • Importing tkinter package
  • Creating a tkinter window with name window
  • Getting width and height of the desktop screen using winfo_screenwidth() in variable width and winfo_screenheight() in variable height respectively.
  • Setting size of tkinter window using geometry () by setting dimensions equivalent to widthxheight.
  • Giving title to the window, here ‘Geeks For Geeks’
  • Creating a label with text ‘Hello Tkinter’ (just for display to the user here)
  • Placing the label widget using pack()
  • Closing the endless loop of windows by calling mainloop()

Program:

Python3




# importing tkinter gui
import tkinter as tk
 
#creating window
window=tk.Tk()
 
#getting screen width and height of display
width= window.winfo_screenwidth()
height= window.winfo_screenheight()
#setting tkinter window size
window.geometry("%dx%d" % (width, height))
window.title("Geeeks For Geeks")
label = tk.Label(window, text="Hello Tkinter!")
label.pack()
 
window.mainloop()


Output:

Method 3: Using state() function

Syntax:

window_name.state('zoomed') 

We will set the parameter of state() to ‘zoomed’ for setting the size of our window to fullscreen by maximizing the window.

Approach:

  • Importing tkinter package
  • Creating a tkinter window with name window
  • Setting the window attribute state as ‘zoomed’
  • Giving a title to the window, here ‘Geeks For Geeks’
  • Creating a label with text ‘Hello Tkinter’ (just for display to the user here)
  • Placing the label widget using pack()
  • Closing the endless loop of windows by calling mainloop()

Result:

We get an output tkinter WINDOW which is already maximized. 

Program

Python3




# importing tkinter for gui
import tkinter as tk
 
# creating window
window = tk.Tk()
 
# setting attribute
window.state('zoomed')
window.title("Geeks For Geeks")
 
# creating text label to display on window screen
label = tk.Label(window, text="Hello Tkinter!")
label.pack()
 
window.mainloop()


Output:

Output using window_name.state(‘zoomed’) 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads