Python Forum
Canvas Text Width/Height
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Canvas Text Width/Height
#1
I am trying to figure out what the width and height of the text I am creating in Canvas are. I have tried using bbox as well as winfo_width()/winfo_height().
My pycharm doesn't seem to recognize winfo and gives me this error: "'int' object has no attribute 'winfo_width'".
When I do bbox, it gives me the same 4 coordinates, no matter how much I increase my text size: (-2 -2 3 3).
canvas1 = Canvas(root, width=self.widthImg, height=self.heightImg, borderwidth=0, highlightthickness=0, bg="white") 
text = canvas1.create_text(0, 0, font=(self.font.get(), self.inputSize.get()), fill="white", text=self.inputText.get())
x,y,x1,y1 = canvas.bbox(text)
print(x,y,x1,y1)
Any ideas?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter reduce OptionMenu height euras 2 4,666 May-25-2021, 09:14 PM
Last Post: euras
  How to place global tk text widget in class or on canvas puje 1 2,333 Jul-04-2020, 09:25 AM
Last Post: deanhystad
  What units does the width parameter of a tkinter Listbox use? Pedroski55 2 5,592 Jul-04-2020, 08:17 AM
Last Post: deanhystad
  [Tkinter] Align the width of the entrys with the column captions Particledust 0 1,725 Apr-23-2020, 08:32 AM
Last Post: Particledust
  Tkinter - Need Help setting Height of a TextInputBox itslewis 1 1,556 Mar-22-2020, 02:37 AM
Last Post: deanhystad
  [Tkinter] Resizing image inside Canvas (with Canvas' resize) Gupi 2 25,106 Jun-04-2019, 05:05 AM
Last Post: Gupi
  [Tkinter] Lock Text Widget height Oxylium 3 4,221 Feb-14-2019, 10:13 PM
Last Post: woooee
  [Tkinter] Scroll bar height is not fixed with Text widget MeeranRizvi 2 15,463 Feb-06-2017, 12:24 PM
Last Post: MeeranRizvi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020