views:

534

answers:

2

I'm starting to learn about Tkinter. I'd like to have a container widget ( Frame ), where the user could add as many textfields as needed by the application. The application starts with a textfield, and a button below that textfield. When the user presses the button, a new text entry will be added below the first one ( this may be repeated countless times ). In the window's center, there will be a Text widget, used to display text :)

However, I noticed this in the documentation:

This widget is used to implement scrolled listboxes, canvases, and text fields.

Is there a way to use the Scrollbar with a Frame?

+2  A: 

If you can use Tix, there is the ScrolledWindow widget which has a window Frame and one or two Scrollbar widgets:

import Tix as tk

r= tk.Tk()
r.title("test scrolled window")
sw= tk.ScrolledWindow(r, scrollbar=tk.Y) # just the vertical scrollbar
sw.pack(fill=tk.BOTH, expand=1)
for i in xrange(10):
    e= tk.Entry(sw.window)
    e.pack()
r.mainloop()

Change the size of the root window. You will want to add code to the focus_get event of the Entry widgets to scroll the ScrolledWindow when tabbing through the keyboard.

Otherwise, you will have to use a Canvas widget (you can add Label, Entry and Text subwidgets) and write a lot more code yourself to implement your required functionality.

ΤΖΩΤΖΙΟΥ
+2  A: 

the problem with Tix is that they don't have a Windows binary installer.

here's an example that should get you started:

http://effbot.org/zone/tkinter-autoscrollbar.htmlink text

reckoner
I don't think this issue is relevant. I've just downloaded Python 2.6.6 for windows, and it comes with Tix. So, it seems to work just as well as Tkinter.
Denilson Sá
Thanks! That was a big help.
reckoner