- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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 find out the size of a canvas item in Tkinter?
To find the minimum height and width of canvas items, we can use the bounding box property of Canvas. Basically, a bounding box property enables the canvas item to return the position inside the canvas. Initially, every item in the bbox(item) method defines the minimum and maximum width and height of the item.
Example
#Import required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the geometry of the window win.geometry("750x250") #Initialize a Canvas canvas= Canvas(win, width= 600, height= 200) #Add a text inside the Canvas text= canvas.create_text(300,20, text= "This is a New Line Text", font=16,anchor= "n") canvas.pack() #Finding the width and height of canvas Items bounds= canvas.bbox(text) width= bounds[3]-bounds[0] height= bounds[3]- bounds[1] print(width) print(height) win.mainloop()
Output
Running the above code will display a window that contains a Canvas Item (Text). It will print the size of the item in the terminal.
The size of the canvas item will be,
-154 23
- Related Articles
- How to set the font size of a Tkinter Canvas text item?
- How do I update images on a Tkinter Canvas?
- How do I get the background color of a Tkinter Canvas widget?
- How to insert an image in a Tkinter canvas item?
- How do I set a minimum window size in Tkinter?
- How do I change button size in Python Tkinter?
- Python Tkinter – How do I change the text size in a label widget?
- How do I find the size of a Java list?
- How can I change the text of the Tkinter Listbox item?
- How do you create a Button on a Tkinter Canvas?
- How do I change the background of a Frame in Tkinter?
- How do I get the index of an item in Tkinter.Listbox?
- How do I make a transparent canvas in HTML5?
- How do I set the size of a list in Java?
- How do I close a tkinter window?

Advertisements