Is there a way to draw vertical text in Tkinter library? (Python recommended)
textID = w1.create_text(5, 5, anchor="nw")
w1.itemconfig(textID, text = "This is some text")
Since people are being linked to this answer, I'll add an update.
In tcl 8.6, the create_text method got an angle
option . You can check your tcl version with Tkinter.TclVersion
. If you have 8.6 or greater, you can use:
textID = w1.create_text(5, 5, anchor="nw", angle=90)
If you are asking whether tkinter.Canvas.create_text
has something like this:
textID = w1.create_text(5, 5, anchor="nw", orient=tkinter.VERTICAL)
then the answer is no. The create_text
method can only create horizontal text.
However, you can use str.join
to create vertical text:
from tkinter import Tk, Canvas
root = Tk()
canvas = Canvas()
canvas.grid()
canvas.create_text((10, 5), text="\n".join("This is some text"), anchor="nw")
root.mainloop()
Example:
While this may not be as elegant as simply setting an option on the create_text
method, it does work.
I don't know any way to make vertical text in tkinter, but you can just make an image of the vertical text you want
vertical_text = PhotoImage(file = "<your file name>.gif") canvas.create_image(x, y, image = vertical_text)
Here is a screenshot from a tkinter window in a program I'm making which lets you revise words
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.