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
Selected Reading
How to display full-screen mode on Tkinter?
Tkinter displays the application window by its default size. However, we can create a full-screen window using the attributes() method. This method assigns properties to tkinter windows such as transparentcolor, alpha, disabled, fullscreen, toolwindow, and topmost.
Basic Full-Screen Window
Use attributes('-fullscreen', True) to make the window occupy the entire screen ?
# Import the tkinter library
from tkinter import *
# Create an instance of tkinter frame
win = Tk()
# Set the geometry (will be overridden by fullscreen)
win.geometry("650x250")
# Add a text label with font properties
label = Label(win, text="Hello World!", font=('Times New Roman bold', 20))
label.pack(padx=10, pady=10)
# Create a fullscreen window
win.attributes('-fullscreen', True)
# Add instructions for exiting
exit_label = Label(win, text="Press Alt+F4 to exit fullscreen", fg="gray")
exit_label.pack(pady=5)
win.mainloop()
Full-Screen with Exit Button
For better user experience, provide a visible way to exit full-screen mode ?
from tkinter import *
def exit_fullscreen():
win.attributes('-fullscreen', False)
win.geometry('800x600')
def toggle_fullscreen():
current_state = win.attributes('-fullscreen')
win.attributes('-fullscreen', not current_state)
win = Tk()
win.title("Full-Screen Demo")
# Main content
label = Label(win, text="Full-Screen Tkinter Window", font=('Arial', 24))
label.pack(pady=50)
# Control buttons
button_frame = Frame(win)
button_frame.pack(pady=20)
exit_btn = Button(button_frame, text="Exit Full-Screen", command=exit_fullscreen)
exit_btn.pack(side=LEFT, padx=10)
toggle_btn = Button(button_frame, text="Toggle Full-Screen", command=toggle_fullscreen)
toggle_btn.pack(side=LEFT, padx=10)
# Enable full-screen
win.attributes('-fullscreen', True)
# Bind Escape key to exit fullscreen
win.bind('<Escape>', lambda e: exit_fullscreen())
win.mainloop()
Key Methods Summary
| Method | Purpose | Usage |
|---|---|---|
attributes('-fullscreen', True) |
Enable full-screen | Makes window cover entire screen |
attributes('-fullscreen', False) |
Disable full-screen | Returns to normal window mode |
bind('<Escape>', function) |
Keyboard shortcut | Exit full-screen with Escape key |
Common Use Cases
Full-screen mode is useful for:
- Presentations − Displaying slides without window borders
- Games − Immersive gaming experience
- Kiosks − Public terminals and information displays
- Media players − Video playback without distractions
Conclusion
Use attributes('-fullscreen', True) to create full-screen Tkinter applications. Always provide an exit method like Escape key binding or visible buttons for better user experience.
Advertisements
