python TK scrollbar problem

Discussion in 'Python' started by Ray, May 1, 2007.

  1. Ray

    Ray Guest

    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()
     
    Ray, May 1, 2007
    #1
    1. Advertising

  2. Ray

    James Stroud Guest

    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/tkinter/introduction/x7583-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/python-list/2007-February/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
     
    James Stroud, May 1, 2007
    #2
    1. Advertising

  3. Ray

    Ray Guest

    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/tkinter/introduction/x7583-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/python-list/2007-February/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
     
    Ray, May 1, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Goffin
    Replies:
    2
    Views:
    625
    Goffin
    Aug 5, 2005
  2. Z
    Replies:
    2
    Views:
    5,318
  3. Paul J. Le Genial

    horizontal scrollbar problem in frame with IE

    Paul J. Le Genial, Mar 9, 2005, in forum: HTML
    Replies:
    13
    Views:
    2,347
    Paul J. Le Genial
    Mar 14, 2005
  4. Arjen
    Replies:
    0
    Views:
    772
    Arjen
    Feb 28, 2006
  5. Alex

    ScrollBar? Does it exist just WEB ScrollBar Control?

    Alex, Apr 1, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    272
    Alvin Bruney [MVP]
    Apr 4, 2004
Loading...

Share This Page