redcreeper14385

Untitled

Jul 25th, 2021
653
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ScrollableFrame(ttk.Frame):
  2.     def __init__(self, container, *args, **kwargs):
  3.         super().__init__(container, *args, **kwargs)
  4.         canvas = tk.Canvas(self)
  5.         scrollbar = ttk.Scrollbar(self, orient="vertical", command=canvas.yview)
  6.         self.scrollable_frame = ttk.Frame(canvas)
  7.         self.scrollable_frame.bind(
  8.             "<Configure>",
  9.             lambda e: canvas.configure(
  10.                 scrollregion=canvas.bbox("all")
  11.             )
  12.         )
  13.         canvas.create_window((0, 0), window=self.scrollable_frame, anchor="nw")
  14.         canvas.configure(yscrollcommand=scrollbar.set)
  15.         canvas.pack(side="left", fill="both", expand=True)
  16.         scrollbar.pack(side="right", fill="y")
  17. window = tk.Tk()
  18. window.geometry('960x540')
  19. window.title("Peruse for reddit")
  20. post_frame = ScrollableFrame(window)
  21. for i in range(50):
  22.     ttk.Label(post_frame.scrollable_frame, text="Sample scrolling label").pack()
  23. post_frame.pack()
  24. window.mainloop()
RAW Paste Data