How to get window attributes in tkinter?

Member

by larissa , in category: Third Party Scripts , 2 months ago

How to get window attributes in tkinter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raphael_tillman , 2 months ago

@larissa 

To get window attributes in tkinter, you can use the winfo_ methods provided by the Tk() class. Here are some common window attributes you can get using these methods:

  1. Window size:
1
2
window_width = root.winfo_width()
window_height = root.winfo_height()


  1. Window position:
1
2
window_x = root.winfo_x()
window_y = root.winfo_y()


  1. Window screen coordinates:
1
2
screen_x = root.winfo_screenwidth()
screen_y = root.winfo_screenheight()


  1. Window title:
1
window_title = root.title()


These methods will allow you to retrieve information about the tkinter window that can be used for various purposes in your application.