Hi,
I am asking here three question together rather than making separate threads for each question.
I am making an application where I can load images in a canvas. I load the image with file menu askopenfilename dialog box. Something like this:

class MyApp(object):
    def __init__(self, master):
        frame = tk.Frame(master)
        frame.pack()
        
        self.canvas = tk.Canvas(width=520, height=350)
        self.canvas.pack(side=BOTTOM)
        self.canvas.config(borderwidth=1, bg='black')

        menu = tk.Menu(master)
        root.config(menu=menu)
        # File menu
        filemenu = tk.Menu(menu, tearoff=0)
        menu.add_cascade(label="File", menu=filemenu)
        filemenu.add_command(label="New          Ctrl+N", command=self.new_file)
        filemenu.add_command(label="Open...      Ctrl+O", command=self.file_open)

1/ could someone kindly show me how to move that image with mouse. First, select the image and than drag and drop on the canvas?
2/ When i load the second image, it deletes the first image. I want to know how to over load images one by one and than select them individually?
3/ How to center the canvas?

Thanks
Regards

Hi,
thanks, but I m still having some problem. Like, i am loading the image manually, while ur example loads the image as soon as i run the programme. This is what my file_open callback looks like;

def file_open(self):
        """open a file to read"""
        # self.canvas.delete(ALL)
        filename = tkfd.askopenfilename(filetypes=myFormats)
        if filename != '':
            im = Image.open(filename)
            if im.mode != "RGBA":
                im = Image.open(filename).convert("RGBA")
                source = im.split()
                R, G, B, A = 0, 1, 2, 3
                mask = im.point(lambda i: i> 0 and 255)
                source[A].paste(mask)
                im = Image.merge(im.mode, source)

        self.graphic = ImageTk.PhotoImage(image=im)
        self.canvas.create_image(100,100, image=self.graphic)

Could you kindly show me how to get the loading image?

Thanks
Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.