- 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
Advertisements