[Tkinter-discuss] Scrollbar for thumbnails

Bryan Oakley bryan.oakley at gmail.com
Fri Jan 11 16:06:22 EST 2019


The canvas can only scroll things added to the canvas with the create_*
functions (create_image, create_window, create_line, etc). You cannot add
widgets to the canvas with pack, place, or grid, and then be able to scroll
them.


On Fri, Jan 11, 2019 at 1:15 PM Mario St-Gelais <mario.stg at videotron.ca>
wrote:

> I am having a terrible time wrapping this under my head.
>
> What is missing here to have the scrollbar working.
>
> Everything is displayed fine.  But the slider of the scrollbar is full
> length. i.e. same height as outerframe.  which is same size as the canvas.
>
>      def setup(self):
>          c = 0
>          r = 0
>          outer_frame = Frame(self, bg='red', padx=2, pady=2)
>          outer_frame.pack()
>          scrollbar = Scrollbar(outer_frame)
>          scrollbar.pack( side = RIGHT, fill=Y )
>
>          canvas = Canvas(outer_frame, height=100,
> scrollregion=(0,0,300,300), yscrollcommand=scrollbar.set)
>          canvas.pack(side=LEFT, expand=YES, fill=BOTH)
>          scrollbar.config(command=canvas.yview)
>
>          for f in os.listdir(self.thumbnail_folder):
>              fpath = os.path.join(self.thumbnail_folder, f)
>              photo = PhotoImage(file=fpath)
>              photo_frame = Frame(canvas, bg='white', padx=2, pady=2)
>              lbl_photo = Label(photo_frame, image=photo, text=f)
> lbl_photo.bind("<ButtonRelease-1>",self.photo_click)
>              lbl_photo.image=photo
>              lbl_photo.pack()
>              lbl_name = Label(photo_frame, text=f.split('.')[0])
> lbl_name.bind("<ButtonRelease-1>",self.photo_click)
>              lbl_name.pack()
>              photo_frame.grid(row=r, column=c)
>              if c > 2:
>                  c = 0
>                  r = r + 1
>              else:
>                  c = c + 1
>
> Regards
>
> Mario St-Gelais
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> https://mail.python.org/mailman/listinfo/tkinter-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20190111/c7d49e2e/attachment.html>


More information about the Tkinter-discuss mailing list