- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the screen size in Tkinter?
Tkinter initially creates a window or frame object where all the widgets, frame are displayed.
Tkinter components adjust the window size and width according to user-defined geometry.
In order to get the screen size, we can use winfo_screenwidth() which returns the screen width and winfo_screenheight() for the height of the screen in pixels.
In this example, we will print the screen size as the output,
#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("650x250") #Get the current screen width and height screen_width = win.winfo_screenwidth() screen_height = win.winfo_screenheight() #Print the screen size print("Screen width:", screen_width) print("Screen height:", screen_height) win.mainloop()
Running the code will display a window and print the screen size.
Screen width: 1366 Screen height: 768
- How to detect the screen size of iPhone 5?
- How to center a window on the screen in Tkinter?
- How to support different screen size in Android?
- How to display full-screen mode on Tkinter?
- How to create a Splash Screen using Tkinter?
- How to create a simple screen using Tkinter?
- Creating Tkinter full-screen application
- How to make a GridLayout fit screen size in Android?
- How to resize the background image to window size in Tkinter?
- How to get the Tkinter Label text?
- How to get full screen activity in android?
- How to get screen DPI programmatically in Android?
- How to set the font size of Entry widget in Tkinter?
- Tkinter-How to get the current date to display in a tkinter window?