Set Tkinter Window Fullscreen at starting – Python
In this tutorial, we will learn how to set the tkinter window at full screen size when starting the window or running the program.
I will show you different methods to do the same. All the methods might be slightly different from each other and you can choose which one is suited for you.
Set full screen of Tkinter window using geometry method
Here we will use the geometry method of Tkinter and in that method, we will pass the screen size (width and height) as one of our arguments. Let’s check it through an example:
import tkinter as tk newWindow = tk.Tk() newWindow.geometry("{}x{}+0+0".format(newWindow.winfo_screenwidth(),newWindow.winfo_screenheight())) newWindow.mainloop()
You can see, on line number 3, I have placed the curly braces empty and the screen height and width will be placed there as we are using format(newWindow.winfo_screenwidth(),newWindow.winfo_screenheight())
You can remove +0+0 as those are not necessary here, those are for positioning our window on the screen.
So we can also use the same like this:
import tkinter as tk newWindow = tk.Tk() newWindow.geometry(f"{newWindow.winfo_screenwidth()}x{newWindow.winfo_screenheight()}") newWindow.mainloop()
The output will be the same.
Set Tkinter window full sized using attributes
This is much simpler but it is slightly different from the previous one as it actually makes the window full-screen. (Like we play movies on our display using full-screen option)
import tkinter as tk newWindow = tk.Tk() newWindow.attributes('-fullscreen', True) newWindow.mainloop()
Here we are giving -fullscreen
as an argument and setting it to True
that’s all. Note that T should be in capital for True.
Set full screen window using state method
This is the easiest of all the methods to remember.
import tkinter as tk newWindow = tk.Tk() newWindow.state("zoomed") newWindow.mainloop()
I have tested all of these. I suggest you to test on your machine and see how it works.
Leave a Reply