Kind time of the day, there is a frame, I put the canvas in it, it is larger than the window size, so I added scrolbars, everything works, great. On the canvas, in the center, I drew the axes, vertical and horizontal.

if self.show_cross.get() == True: self.canvas.create_line(self.cw/2, 0, self.cw/2, self.ch, dash=(3,2)) self.canvas.create_line(0, self.ch/2, self.cw, self.ch/2, dash=(3,2)) 

Where self.cw and self.ch are the dimensions of the canvas. Now I need to position the canvas, that is, so that when the program starts, the crosshair is in the center of the screen, that is, something like scroll_to, but I don’t understand how to do this?

    1 answer 1

    Found in the open spaces

     offset_x = +1 if scroll_x >= 0 else 0 offset_y = +1 if scroll_y >= 0 else 0 self.canvas.xview_moveto(float(scroll_x + offset_x)/new_width) self.canvas.yview_moveto(float(scroll_y + offset_y)/new_height) 

    This solution works even if the canvas is smaller than the size of the widget (that is, scroll_x / y may be negative).

    • Hmm ... how to get scroll_x and scroll_y and what is new_width / new_height? - xterro