Get screen size in Tkinter

Tkinter:

Tkinter is a standard Python GUI library that provides a set of tools and widgets to create desktop applications with graphical interface.

  • The name “Tkinter” comes from “Tk interface”.

FUNDAMENTAL STRUCTURE OF TKINTER PROGRAM:

  1. Importing Tkinter modules
  2. Creating the main window for GUI app
  3. Adding widgets to the app
  4. Enter the main event loop

To getĀ  the screen size in Tkinter we use two methods those are "winfo_screenwidth()" and “winfo_screenheight()" fromĀ  TK() window object.

CODE

import tkinter
#create a tkinter root window
root = tkinter.Tk()
#Get the screen width
screen_width = root.winfo_screenwidth()
#print the screen width
print(screen_width)
#Get the screen heigth
screen_height = root.winfo_screenheight()
#print the screen heigth
print(screen_height)
#run the Tkinter main loop
root.mainloop()

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top