简体   繁体   中英

Python scrollable widget in tk

So I have a little issue with a gui in tk (python, code below), the problem being that my scrollbar seems not to be linked to my canvas, though i think i asked it properly ... any hint ?

root = tk.Tk()  # window
root_frame = tk.Frame(root) # main container
root_frame.pack()

container_frame = tk.Frame(root_frame)  # specific container
container_frame.pack(fill="both")

inner_canvas = tk.Canvas(container_frame, width=100, height=100)  # contains the widgets
inner_canvas.grid_propagate(False)  # i heard this is necessary ...
inner_scrollbar = tk.Scrollbar(container_frame, command=inner_canvas.yview)
inner_canvas.configure(yscrollcommand=inner_scrollbar.set)
inner_canvas.pack(fill="both", side="left")
inner_scrollbar.pack(fill="y", side="right")
for k in range(100):  # simulate the homemade widgets i want to add.
    tk.Label(inner_canvas, text=str(k)+" row").grid(row=k, rowspan=1, columnspan=1)

root.mainloop()

The canvas scrollbar will only scroll widgets added to the canvas with create_window . It will not scroll widgets added to the canvas with pack , place or grid .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM