By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

python TK scrollbar problem

P: n/a
Ray
Hi,

would someone tell me how to make scrollbar work under grid?
I think I'm missing something to connect scrollbar with the grid.
following is some sample code. it shows the scrollbar, but it do not work.

Thanks a lot for the help!

Ray

#####code begin########
from Tkinter import *
def mygrid(text,M = []):
while M:
x = M.pop()
x.destroy()
rows = []
count=int(text)
yscroll = Scrollbar(frame_grid, orient='vertical')
yscroll.grid(rowspan=count, column=5, sticky=NS)
M.append(yscroll)
for i in range(count):
cols = []
for j in range(4):
e = Entry(frame_grid, relief=RIDGE)
M.append(e)
e.grid(row=i, column=j, sticky=NSEW)
e.insert(END, '%d.%d' % (i, j))
cols.append(e)
rows.append(cols)

root=Tk()
frame_entry=Frame(root, width=550, height=100)
frame_entry.pack()
text=Entry(frame_entry)
text.pack(side=LEFT)
button=Button(frame_entry, text='generate grid',
command=(lambda:mygrid(text.get())))
button.pack()
frame_space=Frame(root, width=550, height=100)
frame_space.pack()
frame_grid=Frame(root, width=550, height=300, relief=GROOVE)
frame_grid.pack()
frame_exit=Frame(root, width=550, height=100)
frame_exit.pack()
button2=Button(frame_exit, text='exit', command=root.quit)
button2.pack()
root.mainloop()
Apr 30 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ray wrote:
Hi,

would someone tell me how to make scrollbar work under grid?
I think I'm missing something to connect scrollbar with the grid.
following is some sample code. it shows the scrollbar, but it do not work.

Thanks a lot for the help!

Ray

#####code begin########
from Tkinter import *
def mygrid(text,M = []):
while M:
x = M.pop()
x.destroy()
rows = []
count=int(text)
yscroll = Scrollbar(frame_grid, orient='vertical')
yscroll.grid(rowspan=count, column=5, sticky=NS)
M.append(yscroll)
for i in range(count):
cols = []
for j in range(4):
e = Entry(frame_grid, relief=RIDGE)
M.append(e)
e.grid(row=i, column=j, sticky=NSEW)
e.insert(END, '%d.%d' % (i, j))
cols.append(e)
rows.append(cols)

root=Tk()
frame_entry=Frame(root, width=550, height=100)
frame_entry.pack()
text=Entry(frame_entry)
text.pack(side=LEFT)
button=Button(frame_entry, text='generate grid',
command=(lambda:mygrid(text.get())))
button.pack()
frame_space=Frame(root, width=550, height=100)
frame_space.pack()
frame_grid=Frame(root, width=550, height=300, relief=GROOVE)
frame_grid.pack()
frame_exit=Frame(root, width=550, height=100)
frame_exit.pack()
button2=Button(frame_exit, text='exit', command=root.quit)
button2.pack()
root.mainloop()
You are not binding to the Scrollbar.set() method nor are you assigning
the Scrollbar a command. You should try to emulate this:

http://www.pythonware.com/library/tk...3-patterns.htm

You need to also determine exactly what it is you want to scroll. You
probably don't want to scroll frame_grid as that contains your
scrollbar. Google "tkinter scrolled frame". Here is an example:

http://mail.python.org/pipermail/pyt...ry/427886.html

So, a suggestion would be to create a new frame to hold frame_grid and
yscroll and then use yscroll to scroll frame_grid.

James
Apr 30 '07 #2

P: n/a
Ray
James Stroud wrote:
>
You are not binding to the Scrollbar.set() method nor are you assigning
the Scrollbar a command. You should try to emulate this:

http://www.pythonware.com/library/tk...3-patterns.htm

You need to also determine exactly what it is you want to scroll. You
probably don't want to scroll frame_grid as that contains your
scrollbar. Google "tkinter scrolled frame". Here is an example:

http://mail.python.org/pipermail/pyt...ry/427886.html

So, a suggestion would be to create a new frame to hold frame_grid and
yscroll and then use yscroll to scroll frame_grid.

James
entry do not have .yview and yscrollcommand.
I will try to scroll frame_grid with a new frame.

thanks

Ray
May 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.