I tried the following script, in a canvas
that fills the window:
import tkinter as tk
from PIL import Image, ImageTk
from time import *
root = tk.Tk()
root.geometry("500x500")
canvas = tk.Canvas(root)
canvas.pack()
def fill(event):
canvas.config(width = root.winfo_width(), height = root.winfo_height())
root.bind("<Configure>", fill)
img = Image.open("CO2.png")
imgtk = ImageTk.PhotoImage(img)
item = canvas.create_image(15, 15, image = imgtk)
while True:
canvas.moveto(item, canvas.coords(item)[0], canvas.coords(item)[1])
root.update()
sleep(0.5)
This should do nothing, because it's moving an item to where it already is. But in practice, this moves the image towards the positive x and y direction, which means the coordinates from canvas.coords()
is slightly off and do not correspond to canvas.moveto()
.
Here's the used image:
What is happening here?