- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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.
Example
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()
Output
Running the code will display a window and print the screen size.
Screen width: 1366 Screen height: 768
- Related Articles
- How to center a window on the screen in Tkinter?
- How to support different screen size in Android?
- How to detect the screen size of iPhone 5?
- How to create a Splash Screen using Tkinter?
- How to create a simple screen using Tkinter?
- How to display full-screen mode on Tkinter?
- Get the size of the screen, current web page and browser window in JavaScript
- How to make a GridLayout fit screen size in Android?
- How to resize the background image to window size in Tkinter?
- How to get full screen activity in android?
- How to get screen DPI programmatically in Android?
- Tkinter-How to get the current date to display in a tkinter window?
- How to set the font size of Entry widget in Tkinter?
- How to get the Tkinter Label text?
- Creating Tkinter full-screen application

Advertisements