0

enter image description here

I am using Tkinter and CanvasPlus library to rotate the text by 90 degrees but I am not able to rotate. This is the code I am trying

self.circle = self.canvas.create_circle(0, 0, self.circle_radius, fill=self.bg_color, 
                                        outline="green", width=3)

self.label_ready_for_cooking = self.canvas.create_label(0, 0, font=("Arial", 28),
                                                        fg="white", bg=self.bg_color, 
                                                        text="READY\nFOR", anchor="be")

self.canvas.rotate(self.label_ready_for_cooking, 10, 10, 90, unit="deg")

The image is showing but I am not able to rotate the image. How can I do this?

  • 2
    Not sure what image you are talking about, nor what text. Please [edit] your question and clarify. Added a screenshot of the results you are currently getting, too, if possible. – martineau Feb 14 '21 at 11:38
  • 1
    Not sure if this is going to be helpful but: Why don't you use the PIL library? It supports all kinds of image manipulations and the images can be placed on the canvas. – TheLizzard Feb 14 '21 at 11:49
  • I just went through the [wiki](https://github.com/Luke-zhang-04/CanvasPlus/wiki/Widget-Windows#create_label), if I haven't missed, I don't think you can use `rotate` on [Widget Windows](https://github.com/Luke-zhang-04/CanvasPlus/wiki/Widget-Windows) – astqx Feb 14 '21 at 12:26
  • From the canonical tcl/tk documentation: _"Individual items may be moved or scaled using widget commands described below, **but they may not be rotated**."_ – Bryan Oakley Feb 14 '21 at 16:02
  • I added the image. I want this type image. – harshit Feb 14 '21 at 16:19
  • I used the PIL library but when I am using it is throwing a Broken error. – harshit Feb 14 '21 at 16:21

1 Answers1

0

With reference to the GitHub Wiki of this library

CanvasPlus.rotate() There's no easy way to rotate something in tkinter. Usually, there's a lot of math and trig that is put into it. This method uses complex numbers to rotate a polygon clockwise in radians or degrees.

Basically all the transformations are only applicable to polygons and not any of the Widget Windows.

UPDATE

You could achieve what you are looking for by using the angle parameter of create_text in the default Canvas widget of tkinter.

Try this

from tkinter import *

root=Tk()

canvas=Canvas()
canvas.pack()

canvas.create_text(100,100,text='Rotated Text',angle=90)

root.mainloop()

Note that angle option is available in tk 8.6.x. @acw1668

astqx
  • 2,058
  • 1
  • 10
  • 21
  • when I am using this function it is throwing a broken pipe error. – harshit Feb 14 '21 at 16:23
  • @harshit You can not use any transformation methods (like `rotate`) on a `create_label` instance or any widget for that matter, you can only use it on polygons like `create_rectangle`. What you are trying to achieve is not possible with this lib. – astqx Feb 14 '21 at 16:31
  • @harshit I have updated my answer with a possible solution – astqx Feb 14 '21 at 16:41
  • 1
    Note that `angle` option is available in tk 8.6.x. – acw1668 Feb 14 '21 at 16:41
  • By this method, it is throwing broken pipe error. – harshit Feb 15 '21 at 13:30
  • @harshit You might want to look into [this post](https://stackoverflow.com/questions/14207708/ioerror-errno-32-broken-pipe-python). It's not a problem related to this method or PIL as you mentioned in the comments. – astqx Feb 16 '21 at 06:44