Tim Landscheidt
Tim Landscheidt

Reputation: 1400

Is there a tkinter equivalent for Perl/Tk's Scrolled pseudo-widget?

Perl/Tk has a pseudo-widget Tk::Scrolled that takes as its argument another widget and adds a corresponding scrollbar according to options (where to put it in relation to the widget and if to show at all if there is nothing to scroll). For example, to have a listbox with a scrollbar to the right that disappears if the listbox can display all entries you just have to say:

my $Listbox = $MW->Scrolled ('Listbox', -scrollbars => 'oe');

Has tkinter (3.3.2) some equivalent functionality?

Upvotes: 1

Views: 349

Answers (1)

Andrew Johnson
Andrew Johnson

Reputation: 3186

Tkinter has a Scrollbar class that can be used to wrap widgets in a scrollbar. It may not be as concise to configure as perl, but you can set it up to do what you are asking for without too much hassle.

Here are some examples of the scrollbar in use:

from Tkinter import *
root = Tk()

scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)

listbox = Listbox(root)
listbox.pack()

for i in range(100):
   listbox.insert(END, i)

# attach listbox to scrollbar
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)

mainloop()

Upvotes: 3

Related Questions