Python Tkinter - resize canvas after inital declaration

I want to resize the canvas after adding some widgets to it

Example:

from Tkinter import * master = Tk() w = Canvas(master, width=100, height=100) w.config(bg='white') w.create_oval(90,90,110,110, width=0, fill = "ivory3") w = Canvas(master, width=200, height=200) w.pack() mainloop() 

But it seems that when I re-declare the size of the canvas, the objects are deleted. Is it possible to update the canvas after I created some objects on it?

+4
source share
1 answer

What you are looking for is the configure parameter as described here . Basically, something like this should help instead of creating a new canvas.

 w.config(width=200 height=200) 

For reference, the reason that everything was deleted from Canvas, you created a new Canvas with a different size and the same name. If you intend to change the properties of an existing object, you must modify the existing object and not overwrite it. Basically you rewrite something if you declare it equal to something else ( w=Canvas (...))

+9
source

Source: https://habr.com/ru/post/1400079/


All Articles