- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I get the width and height of a Tkinter window?
Tkinter initially creates an instance of a window which is a container that contains all the widgets and the elements. If we want to resize the window, we can use the geometry method by defining the value of width and height.
In order to get the width and height of the tkinter window, we can use winfo_width() and winfo_height() helper methods that help to grab the current width and height of the tkinter window.
# Import tkinter library from tkinter import * # Create an instance of tkinter frame win = Tk() # Set the Geometry win.geometry("750x250") def print_width(): print("The width of Tkinter window:", win.winfo_width()) print("The height of Tkinter window:", win.winfo_height()) # Create a Label Label(win, text="Click the below Button to Print the Height and width of the Screen", font=('Helvetica 10 bold')).pack(pady=20) # Create a Button for print function Button(win, text="Click", command=print_width).pack(pady=10) win.mainloop()
Running the above code will display a window that contains a button.
If you click the button, it will print the current width and height of the tkinter window on the console.
The width of Tkinter window: 750 The height of Tkinter window: 250
- Related Articles
- How do I get rid of the Python Tkinter root window?
- How do I get the height and width of the Android Navigation Bar programmatically?
- How do I close a tkinter window?
- How do I get the height and width of the Android Navigation Bar programmatically using Kotlin?
- How do I position the buttons on a Tkinter window?
- How do I create a popup window using Tkinter?
- How do I create a popup window in Tkinter?
- How do I open a website in a Tkinter window?
- How do I use Tkinter in Python to create line-wrapped text that fills the width of the window?
- How do I create a popup window using Tkinter Program?
- How do I set a minimum window size in Tkinter?
- How do I handle the window close event in Tkinter?
- How do I set browser width and height in Selenium WebDriver?
- How do I insert a JPEG image into a Python Tkinter window?
- How can I get android device screen height, width?