[Python] Is Pillow ImageDraw.Draw.draw and Tkinter units the same?

Discussão em 'Python' iniciado por Stack, Julho 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have a program which writes text based on the size of the image. If the size is 900x900 (tkinter units) then it will write text on 300x300, 300x600, 600x300 and 600x600, but when I try to write that, it only writes on the centre.

    global draw, img_tk
    draw = ImageDraw.Draw(img)
    font = ImageFont.load_default()
    for line in range(1, int(2)+1):
    print(img_tk.height() / int(2) + 1)
    line_coord = (img_tk.height() / int(2) + 1) * line
    for mark in range(1, int(2)+1):
    mark_coord = (img_tk.width() / int(2) + 1) * mark
    print(mark_coord)
    draw.text(xy=(mark_coord, line_coord), text="TESTER", fill=(255,255,255), font=font)


    img_tk = ImageTk.PhotoImage(img)
    image_label.image = img_tk
    image_label.config(image=img_tk)


    Result:

    [​IMG]

    My guess was that the units of the ImageTK and the PIL Image wasn't the same. But I checked and it was so I thought that the ImageTK and the ImageDraw.Draw.draw function took different type of units.

    Continue reading...

Compartilhe esta Página