Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def h_scrollable_area(holder):
- base_frame = Frame(holder, padx=5, pady=5)
- base_frame.pack(fill=BOTH, expand=1)
- base_frame.rowconfigure(0, weight=0)
- base_frame.columnconfigure(0, weight=1)
- can = Canvas(base_frame, bg="white")
- can.pack(side=TOP, expand=1, fill=BOTH)
- scrollArea = Frame(base_frame, bg="white")
- scrollArea.pack(side=TOP, expand=1, fill=BOTH)
- can.create_window(0, 0, window=scrollArea, anchor='nw')
- Scroll = Scrollbar(base_frame, orient=HORIZONTAL)
- Scroll.config(command=can.xview)
- Scroll.pack(side=BOTTOM, fill=X)
- can.config(xscrollcommand=Scroll.set)
- scrollArea.bind("<Configure>", lambda e=Event(), c=can: update_scrollregion(e, c))
- return scrollArea, can ##scrollArea is the frame to put stuff into. can is the Canvas in case you need to bind additional options or extra configurations.
- def update_scrollregion(event, can):
- can.configure(scrollregion=can.bbox("all"))
- pass
- ##usage
- #root = Tk()
- #window = Frame(root)
- #window.pack(side=TOP)
- #scroll, can = h_scrollable_area(window)
- #for i in range(20)
- # Button(scroll, text=i, width=5).pack(side=LEFT)
- #root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement