TKinter Images

You can attach images to the canvas with

Where the example image is located in a image subfolder of the program with type gif. If you wanted to change the image to another type during the execution of the program you would need to use a slightly different initial call which creates a reference to the image:

This can then be updated during the execution of the program with the canvas.itemconfig command.

The reality of this as a background image that changes during the game with levels is slightly different. We have to create an array of background images at the start:

Which are then available in all methods within the game allowing them to be changed by key events:

OTHER COMMANDS

Deleting – You can remove an image from the canvas with canvas.delete(name) where name is the name you give it at the point of creation e.g. using the example above it would be background.

About CDB 360 Articles
Self-Employed Software Developer, Spark, Property Management, Hobby Forestry, Ex-Teacher, Engineering - Wood, Metal, Electrics & Computers. Outdoors - Walk, Cycle, Kitesurf,

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.