Getting screen’s height and width using Tkinter | Python

Tkinter provides some methods with the help of which we can get the current screen height and width.

Following methods can be used to decide height and width :

winfo_screenheight() // Returns screen height in pixels

winfo_screenmmheight() // Returns screen height in mm

winfo_screenwidht() // Returns screen width in pixels

winfo_screenmmwidth() // Returns screen width in mm

 
Code #1: Getting height and width in pixels.



filter_none

edit
close

play_arrow

link
brightness_4
code

# importing tkinter module
from tkinter import * from tkinter.ttk import *
  
# creating tkinter window
root = Tk()
  
# getting screen's height in pixels
height = root.winfo_screenheight()
  
# getting screen's width in pixels
width = root.winfo_screenwidth()
  
print("\n width x height = %d x %d (in pixels)\n" %(width, height))
# infinite loop
mainloop()

chevron_right


Output:

 
Code #2: Getting height and width in mm.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing tkinter module
from tkinter import * from tkinter.ttk import *
  
# creating tkinter window
root = Tk()
  
# getting screen's height in mm
height = root.winfo_screenmmheight()
  
# getting screen's width in mm
width = root.winfo_screenmmwidth()
  
print("\n width x height = %d x %d (in mm)\n" %(width, height))
# infinite loop
mainloop()

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.