SV: Adjust a canvas as the window is resized

K Viltersten tmp1 at viltersten.com
Mon Mar 10 15:12:25 EDT 2008


>> Do i need to set a callback to a canvas
>> in order to "listen" to the root window
>> being resized in order to make it adjust
>> its contents?
>> 
>> If so, how? If not, how do i make the
>> canvas draw a line from one corner to
>> an other?
> 
> import Tkinter as tk
> 
> root = tk.Tk()
> canvas = tk.Canvas(root)
> canvas.pack(expand=True, fill=tk.BOTH)
> line = canvas.create_line(0, 0, 0, 0)
> 
> def resize(event):
>    canvas.coords(line, 0, 0, event.width, event.height)
> canvas.bind("<Configure>", resize)
> 
> root.mainloop()


Super nice! Thanks a million!

-- 

--
Regards
Konrad Viltersten
--------------------------------
sleep    - a substitute for coffee for the poor
ambition - lack of sense to be lazy




More information about the Python-list mailing list