Advertisement
AceScottie

horizontal_scroll.py

Sep 18th, 2019
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. def h_scrollable_area(holder):
  2.     base_frame = Frame(holder, padx=5, pady=5)
  3.     base_frame.pack(fill=BOTH, expand=1)
  4.     base_frame.rowconfigure(0, weight=0)
  5.     base_frame.columnconfigure(0, weight=1)
  6.     can = Canvas(base_frame, bg="white")
  7.     can.pack(side=TOP, expand=1, fill=BOTH)
  8.     scrollArea = Frame(base_frame, bg="white")
  9.     scrollArea.pack(side=TOP, expand=1, fill=BOTH)
  10.     can.create_window(0, 0, window=scrollArea, anchor='nw')
  11.     Scroll = Scrollbar(base_frame, orient=HORIZONTAL)
  12.     Scroll.config(command=can.xview)
  13.     Scroll.pack(side=BOTTOM, fill=X)
  14.     can.config(xscrollcommand=Scroll.set)
  15.     scrollArea.bind("<Configure>", lambda e=Event(), c=can: update_scrollregion(e, c))
  16.     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.
  17. def update_scrollregion(event, can):
  18.     can.configure(scrollregion=can.bbox("all"))
  19.     pass
  20.  
  21. ##usage
  22. #root = Tk()
  23. #window = Frame(root)
  24. #window.pack(side=TOP)
  25. #scroll, can = h_scrollable_area(window)
  26. #for i in range(20)
  27. #   Button(scroll, text=i, width=5).pack(side=LEFT)
  28. #root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement