Tkinter: Clipping a canvas text item

John Roth newsgroups at jhrothjr.com
Sat Feb 21 13:48:38 EST 2004


"Peter Otten" <__peter__ at web.de> wrote in message
news:c17ls5$hmr$04$1 at news.t-online.com...
> Is there a way to limit both width and height of a canvas text item?
> My current workaround seems clumsy:
>
> import Tkinter as tk
> root = tk.Tk()
> canvas = tk.Canvas(root, width=400, height=200, bg="white")
> canvas.pack()
>
> # simulate a clipped text item - never transparent :-(
> s = "The long and winding road.."
> lbl = tk.Label(root, text=s, anchor=tk.W, bg=canvas["bg"])
> canvas.create_window(50, 80, width=100, height=20,
>     window=lbl,
>     anchor=tk.NW)
>
> root.mainloop()
>
> Thanks,
> Peter

I suppose if I absolutely had to do it, I'd clip by hiding the edges
under something else. Or else I'd find another toolkit that can
do the job. Thankfully, I don't have to do it.

John Roth





More information about the Python-list mailing list