

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Getting screens height and width using Tkinter Python
Tkinter is the library which gives GUI programming capability to python programs. As part of GUI creation we need to create screen layouts of different sizes and depth. In this program we will see how to calculate the size of a screen in terms of pixels as well as in mm. We can also get the depth of the screen in pixels. There are various methods available as part of Tkinter which we use for this.
Example
from tkinter import * # creating tkinter window base = Tk() #screen's length and width in pixels and mm length_1= base.winfo_screenheight() width_1= base.winfo_screenwidth() length_2 = base.winfo_screenmmheight() width_2 = base.winfo_screenmmwidth() #screen Depth screendepth = base.winfo_screendepth() print("\n width x length (in pixels) = ",(width_1,length_1)) print("\n width x length (in mm) = ", (width_2, length_2)) print("\n Screen depth = ",screendepth) mainloop()
Running the above code gives us the following result
Output
width x length (in pixels) = (1600, 900) width x length (in mm) = (423, 238) Screen depth = 32
- Related Questions & Answers
- Getting the Largest Window Height and Width of the Console in C#
- How do I get the width and height of a Tkinter window?
- Change the width and height of element using CSS
- The width and height properties in CSS
- Width and Height of Elements in CSS
- How to set width and height of an element using jQuery?
- How to set the min and max height or width of a Frame in Tkinter?
- How to set the height/width of a Label widget in Tkinter?
- Set the height and width of an image using percent with CSS
- Python Tkinter – Set Entry width 100%
- How to set viewport height and width in CSS
- How to set cell width and height in HTML?
- How to use height and width attributes in HTML?
- Crop Canvas / Export HTML5 Canvas with certain width and height
- Get the width and height of a three-dimensional array
Advertisements