# Getting screens height and width using Tkinter Python

PythonServer Side ProgrammingProgramming

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
Published on 23-Dec-2019 09:58:46