How do you keep a widget in view while scrolling? How do you keep a widget in view while scrolling? tkinter tkinter

How do you keep a widget in view while scrolling?


The second option you mentioned could be the one that satisfies your situation, however that is computationally expensive as you will need to delete the button(s) and redraw them over and over relatively to the scrollbar up/down motion. Not only this is ugly by design but it can be an obstacle for any further scalability of your application or even lead to unexpected bugs if your application runs some serious operations.

The only realistic solution I see for your problem is to fix the button(s) on (for example the bottom of) the upper canvas (or whatever region you want to set) and outside the scrollable region as @falsetru commented you.


You can put the button out of ScrollWindows:

import Tixfrom Tkinter import *def build_ui(root):    sw = Tix.ScrolledWindow(root, scrollbar=Tix.AUTO)    sw.pack(side=LEFT, fill=Tix.BOTH, expand=1)    for i in range(300):        label1 = Label(sw.window, text="foo")        label1.grid(row=i, column=0)    button = Button(root, text="Quit", command=root.quit)    button.pack(side=RIGHT)root = Tix.Tk()build_ui(root)root.mainloop()