Search code examples
pythonuser-interfacetkinterpygamewxpython

How do I make a combined object with string and image in Python?


I am currently trying to make a display canvas and some dynamically moving objects on the white canvas. The character should look like below:

example image - character and text

This symbolistic character should be clickable, not just the octangle but including the numeric objects around the image.

I heard about Tkinter, which is a built-in GUI library for Python, and I guess Tkinter or Pygame would be very useful to implement a character like above. But I have no idea from where I should start. Could you let me know, or at least where to start to learn how to implement a combined character such as the one above?


Solution

  • To implement something like you want in this case in Tkinter, you could use the Tk canvas. This would let you place objects (including pictures, shapes, and text) onto it, and move them around from user-inputs, i.e. key presses or clicks on them.

    There are plenty of tutorials on how to get started with canvas so I won't go into too much detail here. The underlying principle however would be to, after making all your objects, give them a similar tag such as "player", and then interact with the "player" tag whenever you wish to do something with it, such as detect a click on it or move it around the canvas.

    Good luck!