Home > front end >  How to move canvas drawn shapes to have a fixed position on screen?
How to move canvas drawn shapes to have a fixed position on screen?

Time:07-02

I have a GUI that I've made in tkinter using a canvas that has a bar along the left side and a bar along the top containing information. In the remaining area various rectangles are drawn corresponding to the information in those bars I described. The issue is, when you scroll away on the canvas, those events will leave as well.

Basically, I want to create a visual effect like position: fixed is in CSS where these bars on the side and the top stay in place relative to the rest of the canvas so that they don't move from their relative position while scrolling.

I tried making use of the scrollbar commands, but have had trouble making my own function there. I also tried to see if there was an event I could bind to the canvas to track the movement so that I could move the bars myself but I could not find anything.

CodePudding user response:

There is no way to do this directly in the canvas unless you write the code to move the items in the top and left whenever the user scrolls. It would probably require a fair amount of work.

However, it's trivial to have separate canvases for the side and top that do not scroll, and a third canvas that has all of the scrolled data.

CodePudding user response:

I was able to end up solving my own issue by adapting the solution from: How can I add Unscrollable Image to a frame/Canvas?

Simply put, I made my own yview and xview functions that would scroll my desired "bars" with the window by moving the objects.

Special thanks to @jasonharper for his help.

  • Related