Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Creating Tkinter full-screen application
Tkinter initially creates a window that contains application components such as widgets and control bars. We can switch a native-looking application to a full-screen application by using the attributes('-fullscreen', True) method. To make the window full-screen, just invoke the method with the particular window.
Basic Full-Screen Example
Here's how to create a basic full-screen Tkinter application ?
# Import tkinter library
from tkinter import *
# Create an instance of tkinter frame or window
win = Tk()
# Set the geometry of tkinter frame
win.geometry("750x250")
# Create a Text widget
text = Label(win, text="Hello\nWelcome to Tutorialspoint.com!",
font=('Century Schoolbook', 20, 'italic bold'))
text.pack(pady=30)
# Enable full-screen mode
win.attributes('-fullscreen', True)
win.mainloop()
Executing the above code will display a full screen window without window borders or title bar.
Full-Screen with Exit Button
Since full-screen mode hides the window controls, it's good practice to add an exit button ?
from tkinter import *
def exit_fullscreen():
win.quit()
# Create window
win = Tk()
win.geometry("750x250")
# Create content
text = Label(win, text="Full-Screen Application",
font=('Arial', 24, 'bold'))
text.pack(pady=50)
# Add exit button
exit_btn = Button(win, text="Exit", command=exit_fullscreen,
font=('Arial', 14), bg='red', fg='white')
exit_btn.pack(pady=20)
# Enable full-screen
win.attributes('-fullscreen', True)
win.mainloop()
Toggle Full-Screen Mode
You can also create a function to toggle between full-screen and windowed mode ?
from tkinter import *
def toggle_fullscreen():
current_state = win.attributes('-fullscreen')
win.attributes('-fullscreen', not current_state)
# Create window
win = Tk()
win.geometry("800x600")
# Create content
label = Label(win, text="Press F11 to Toggle Full-Screen",
font=('Arial', 18))
label.pack(pady=100)
toggle_btn = Button(win, text="Toggle Full-Screen",
command=toggle_fullscreen,
font=('Arial', 12))
toggle_btn.pack(pady=20)
# Bind F11 key to toggle function
win.bind('<F11>', lambda event: toggle_fullscreen())
# Bind Escape key to exit full-screen
win.bind('<Escape>', lambda event: win.attributes('-fullscreen', False))
win.mainloop()
Key Points
- Use
attributes('-fullscreen', True)to enable full-screen mode - Full-screen mode hides window borders, title bar, and system controls
- Always provide an exit method (button, key binding, or Alt+F4)
- Common key bindings: F11 for toggle, Escape to exit full-screen
Conclusion
Creating full-screen Tkinter applications is straightforward using the attributes('-fullscreen', True) method. Always include exit functionality for better user experience, such as exit buttons or keyboard shortcuts like Escape or F11.
