Reputation: 21
Is it possible to keep the origin of a resizable tkinter.canvas centered without binding a Configure event handler to the canvas? I would like to achieve the same result as the following python script, but without using bind.
I gave up after searching for two hours. Is there a widget option I miss?
import tkinter
from PIL import ImageTk
def centerCanvasOrigin(e):
root.update()
cnv.scan_dragto(round(cnv.winfo_width()/2), round(cnv.winfo_height()/2), 1)
root = tkinter.Tk()
cnv = tkinter.Canvas()
cnv.pack(fill = tkinter.BOTH, expand = 1)
cnv.bind("<Configure>", centerCanvasOrigin)
img = ImageTk.PhotoImage(file="img/image.png")
cnv.create_image(0, 0, image = img)
centerCanvasOrigin(True) #i know, sry about this :)
root.mainloop()
Upvotes: 2
Views: 191
Reputation: 385980
Is it possible to keep the origin of a resizable tkinter.canvas centered without binding a Configure event handler to the canvas?
No, it is not.
Upvotes: 1