key = ""
def key_down (e):
key = e.keysym
def key_up (e):
key = ""
mx = 1
my = 1
def main_proc ():
global mx, my
if key == "Up" and maze [my-1] [mx] == 0:
my = my --1
if key == "Down" and maze [my + 1] [mx] == 0:
my = my + 1
if key == "Left" and maze [my] [mx-1] == 0:
mx = mx --1
if key == "Right" and maze [my] [mx + 1] == 0:
mx = mx + 1
canvas.coords ("MYCHR", mx * 80 + 40, my * 80 + 40)
root.after (300, main_proc)
root = tkinter.Tk ()
root.title ("Move in the maze")
canvas = tkinter.Canvas (width = 800, height = 560, bg = "white")
maze = [
for y in range (7):
for x in range (10):
if maze [y] [x] == 1:
canvas.create_rectangle (x * 80, y * 80, x * 80 + 79, y * 80 + 79, fill = "skyblue", width = 0)
img = tkinter.PhotoImage (file = "mimi_s.png")
canvas.create_image (mx * 80 + 40, my * 80 + 40, image = img, tag = "MYCHR")
What are the roles of tag = "MYCHR" and canvas.coords ("MYCHR", mx * 80 + 40, my * 80 + 40)?
Where did the MYCHR with tag = "MYCHR" come from?
I'm studying with books, but I don't understand, so please.
Answer # 1
The method of pasting the source is different and it is difficult to read, but the answer is as the link shown by 1T2R3M4 in the question column.
The coords () function moves the position of the item specified by the argument to the location of the specified foods. item is specified by id or tag.
The create_image () function creates an image and returns an id. Also, the "name" specified by the argument tag is attached to the image.
So, for the image to be moved by coords, you can specify the id that is set when you make it, but if it is troublesome to carry around the body, an appropriate name (in this case "MY CHR") It means that you can also add and use it.
- python 3x - please teach about the exchange of information with qthead
- python 3x - please tell me about runtimeerror
- python - please tell me about the processing contents of opencv background subtraction
- python 3x - about downloading anaconda
- python - about x-axis adjustment in matplotlib
- python - about "" "of" "" select === = "" "
- python, about the fire spread step of forest fire simulation
- python - about hamiltonian neural networks
- python - about write loop to csv
- about python argument and data definition
- i have a question about basic python problems
- python - (tensorflow) please teach me how to connect labels and indexes
- about image output of python
- python - about downloading youtube videos by youtube-dl
- about processing to exclude the character string group specified from list in python
- python - what i don't understand about yolo9000 (v2)
- about batch change of file name using python
- about the python speedtest code
- about the implementation of combinations in python
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- xcode - pod install [!] no `podfile 'found in the project directory