Open In App

Getting screen's height and width using Tkinter | Python

Last Updated : 14 Sep, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

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_screenwidth() // Returns screen width in pixels

winfo_screenmmwidth() // Returns screen width in mm


  
Code #1: Getting height and width in pixels. 
 

Python3
# 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()

Output: 
 


  
Code #2: Getting height and width in mm. 
 

Python3
# 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()

Output: 
 


 


Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy