How to copy one tkinter object's options when creating another object of the same type? How to copy one tkinter object's options when creating another object of the same type? tkinter tkinter

How to copy one tkinter object's options when creating another object of the same type?


As you can see, itemconfig doesn't return just a dictionary of simple key/value pairs. For each option it will return a tuple made up of the following five items:

  1. option name
  2. option name for the option database
  3. option class for the option database
  4. the default value
  5. the current value

If you want to replicate all of the options, you need the last item returned for each option.

You can do that fairly easily with a dictionary comprehension:

config = canvas.itemconfig(canvas_tag_or_id)new_config = {key: config[key][-1] for key in config.keys()}canvas.create_rectangle(coords, **new_config)

For more information see