0

Using this answer I was trying to display an image together with scrollbars. But the class created by author of this answer always displays the image in the top left corner of the canvas and I needed image to be displayed in the center. Changing zeroes to other coordinates in self.cnvs.create_image(0, 0, anchor='nw', image=self.image) didn't help. So I tried to experiment a bit and replicated the code and tried to create two images (one with zero coordinates and one with nonzero coordinates) and to my surprise the on with nonzero was not in the top left corner. The code I used is:

flowchart_image_frame=Frame(root,width=600,height=400)
canvas=Canvas(flowchart_image_frame,width=600,height=400,bg="white")
image_id=canvas.create_image(0,0,anchor=CENTER,image=img)
image_id2=canvas.create_image(100,100,anchor=CENTER,image=img)
v_scroll=Scrollbar(flowchart_image_frame,orient="vertical",width=20)
h_scroll=Scrollbar(flowchart_image_frame,orient="horizontal",width=20)
canvas.grid(row=0, column=0,  sticky='nsew')
h_scroll.grid(row=1, column=0, sticky='ew')
v_scroll.grid(row=0, column=1, sticky='ns')
flowchart_image_frame.rowconfigure(0, weight=1)
flowchart_image_frame.columnconfigure(0, weight=1)
canvas.config(xscrollcommand=h_scroll.set, yscrollcommand=v_scroll.set)
v_scroll.config(command=canvas.yview)
h_scroll.config(command=canvas.xview)
canvas.config(scrollregion=canvas.bbox('all'))
flowchart_image_frame.place(x=351,y=0)

So I would like to know why is it that when I created only one image with nonzero coordinates the image still appeared in the top left corner and why did adding additional image changed this, and is there some way to fix this so that I can create only one image and get it to not appear in the top left corner ?

The image I was using:enter image description here

0 Answers0