
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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 Articles
- Getting the Largest Window Height and Width of the Console in C#
- How do I get the width and height of a Tkinter window?
- Python Tkinter – Set Entry width 100%
- Change the width and height of element using CSS
- How to set the height/width of a Label widget in Tkinter?
- How to set the min and max height or width of a Frame in Tkinter?
- How to set width and height of an element using jQuery?
- Set the height and width of an image using percent with CSS
- How to animate div width and height on mouse hover using jQuery?
- The width and height properties in CSS
- Width and Height of Elements in CSS
- Copy from clipboard using Python and Tkinter
- How to make an OptionMenu maintain the same width using tkinter?
- How to set viewport height and width in CSS
- How to use height and width attributes in HTML?

Advertisements