python 3.x - How do I position a button to a canvas, not to the screen using Tkinter 3 -
i have canvas image i'd use background. problem when position button correct place, , try scroll down, button moves screen instead of staying want on canvas.
frame = frame(self) frame.pack() mapimg = photoimage(file='fo4-pip-map.png') canvas = canvas(frame, width=2048, height=2048, scrollregion=(0,0,2048,2048)) canvas.create_image(0,0, image=mapimg, anchor='nw') canvas.image = mapimg xscrollbar = scrollbar(frame, orient=horizontal) xscrollbar.pack(side=bottom, fill=x, anchor='s') yscrollbar = scrollbar(frame, orient=vertical) yscrollbar.pack(side=right, fill=y, anchor='e') xscrollbar.config(command=canvas.xview) yscrollbar.config(command=canvas.yview) canvas.config(xscrollcommand=xscrollbar.set, yscrollcommand=yscrollbar.set) canvas.pack(side=left, expand=true, fill=both) vaultimg = photoimage(file='vault.png') vaultimg = vaultimg.zoom(5) vaultimg = vaultimg.subsample(32) vault111button = button(canvas, width=30, height=30, borderwidth=0, image=vaultimg, command=lambda: controller.show_frame('vault111')) vault111button.image = vaultimg vault111button.place(x=150, y=100)
the place
geometry manager places children @ fixed offset parent - in particular, scrolling of canvas doesn't apply them. rid of last line, , instead use:
canvas.create_window(150, 100, window=vault111button)
Comments
Post a Comment