オフラインGPSシステムを改善しようとしています。私は次のように移動するような画像を扱うためのPythonコードを書いた。私はこのコードを変更して複数の画像を処理したいのです。このコードは単一の画像を読み込むことができ、マウスの動きによってキャンバス内を移動することができます。私はこのプログラムに複数の画像を同時にロードし、各画像部分をGoogleマップなどの単一の画像として表示する必要があります。複数の画像を同じ時間に同じ画像として表示および移動する方法python Tkinter?
from Tkinter import *
root = Tk(); root.geometry("600x400")
c = Canvas(root, width = 600, height = 400, bg = "white"); c.pack()
class MainFrame:
"""Class to move an image on a Canvas screen (Python 2.5)"""
def __init__(self, image):
self.__image = image
self.__x, self.__y = 250,250
self.__picture = c.create_image(self.__x, self.__y, image = self.__image)
self.__move = False
c.bind("<Button-1>", self.startMovement)
c.bind("<ButtonRelease-1>", self.stopMovement)
c.bind("<Motion>", self.movement)
c.create_polygon((0, 100, 50, 0, 100, 100), fill="#4eccde")
def startMovement(self, event):
global initi_x
global initi_y
initi_x = event.x
initi_y = event.y
self.__move = True
def stopMovement(self, event):
self.__move = False
def movement(self, event):
if self.__move:
global initi_x
global initi_y
c.delete(self.__picture)
x_axis = initi_x - event.x
y_axis = initi_y - event.y
self.__x -= x_axis
self.__y -= y_axis
print("x is ",event.x)
print("y is ",event.y)
#self.__x, self.__y = event.x ,event.y
self.__picture = c.create_image(self.__x, self.__y, image = self.__image)
initi_x = event.x
initi_y = event.y
c[ "cursor" ] = "hand2"
if __name__ == "__main__":
im = PhotoImage(file = "new1.gif")
m = MainFrame(im)
mainloop()
コードのインデントとスペースを親切に修正できますか? –