# -*- coding: utf-8 -*-
"""
画像の読み込みと配置と移動（上下左右，ボタン）
"""

import tkinter as tk


def main():
    base = tk.Tk()
    base.title("$u_id")

    canvas = tk.Canvas(base, width=400, height=300)
    canvas.pack()

    # 画像の読み込み
    img1 = tk.PhotoImage(file="img1.png")
    img2 = tk.PhotoImage(file="img2.png")

    # 画像の配置
    # 同じ座標でもanchorの指定で位置取りが変わる
    id_img1 = canvas.create_image(200, 150, image=img1, anchor=tk.SE)
    id_img2 = canvas.create_image(200, 150, image=img2)
    id_img3 = canvas.create_image(200, 150, image=img1, anchor=tk.NW)

    # ボタンの設定
    bt_L = tk.Button(base, text="←←←", command=lambda:canvas.move(id_img2, -10, 0))
    bt_R = tk.Button(base, text="→→→", command=lambda:canvas.move(id_img2, +10, 0))
    bt_U = tk.Button(base, text="↑↑↑", command=lambda:canvas.move(id_img2, 0, -10))
    bt_D = tk.Button(base, text="↓↓↓", command=lambda:canvas.move(id_img2, 0, +10))

    bt_L.pack(side=tk.LEFT)
    bt_R.pack(side=tk.RIGHT)
    bt_U.pack(side=tk.TOP)
    bt_D.pack(side=tk.BOTTOM)

    base.mainloop()  # GUIを待機


if __name__ == "__main__":
    main()
