-1

I'm a bit new to tkinter but really enjoy using it. I have a little problem with the scrollbar:
I'm using python 3.6 8 on ubuntu 18.04. I am trying to develop a software for a school's management.
In one of the toplevel using grid geometry I have many rows with 5 columns including 3 labels, 1combobox and 1 button. All the same for 35 rows. I tried the scrollbar but its just giving me small bar staying above widgets.

import tkinter 
frame1 = tkinter.Frame(root).grid(row=0, column=0)
bar = tkinter.Scrollbar(frame1).grid(column=6, row=0, sticky=ns)
canvas = tkinter.Canvas(frame1, scrollregion=(0, 0, 1000, 1000), yscrollcommand=bar.set).grid(row=0, column=0) 
frame = tkinter.Frame(canvas).grid(column=0, row=0) 

 # I placed the widgets in the frame here

canvas.config(scrollregion=canvas.bbox(All))

window.mainloop()

Please help

Dan
  • 1
  • 4
  • Does this answer your question? [Adding a scrollbar to a group of widgets in Tkinter](https://stackoverflow.com/questions/3085696/adding-a-scrollbar-to-a-group-of-widgets-in-tkinter) – j_4321 Nov 05 '19 at 12:08
  • The pack geometry makes it a bit confusing. I just need the grid method most especially for the tkinter on this python 3.6.8 – Dan Nov 05 '19 at 14:20
  • Then show us a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Right now we can't tell what's wrong with your code, though adding the `sticky='ns'` option when you grid the scrollbar should help fix your issue. – j_4321 Nov 05 '19 at 15:14
  • `import tkinter` `canvas = tkinter.Canvas(window, width=900, height=900).grid(column=0, row=0, rowspan=50)` `frame = tkinter.Frame(canvas, width=900, height=900).grid(column=0, row=0, rowspan=50)` `bar = tkinter.Scrollbar(windows).grid(column=0, row=0, rowspan=50)` `lbl1 = tkinter.Label(frame, text=......).grid(column=1, row=1)` `.` `.` `lbl35` `combo1 = tkinter.Combobox(frame).grid(column=1, row=1)` `.` `.` `combo35` `btn1 = tkinter.Button(frame, text=......).grid(column=1, row=1)` `.` `.` `btn35` `window.mainloop()` – Dan Nov 05 '19 at 20:07
  • Pls I just need how to go about it most especially with grid geometr – Dan Nov 05 '19 at 20:10
  • 1
    Could you edit your question instead of giving the code in the comment please? – j_4321 Nov 07 '19 at 08:42
  • The code you added doesn't show any attempt to connect the scrollbar to the canvas. Also you need to put the widgets you want to scroll inside the frame which is in the canvas. You can use the answer from https://stackoverflow.com/questions/3085696/adding-a-scrollbar-to-a-group-of-widgets-in-tkinter, just replace `pack` by `grid` when putting the canvas and scrollbar in your GUI. – j_4321 Nov 07 '19 at 14:46
  • I tried using the link procedure but not really understanding it concerning my plight. Please I have updated the question. The scrollbar shows, widgets shows beneath thereby not serving its purpose. Please where have I gone wrong again. – Dan Nov 19 '19 at 13:31
  • I still get a bunch of errors when I try to run your code sample which are totally irrelevant to your issue: root is not defined, Nonetype has no attribute ... (see https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name) which I don't want to fix to see where is your actual problem. Have a look at https://stackoverflow.com/questions/43731784/tkinter-canvas-scrollbar-with-grid, the answer is using grid only. By the way this is the first result when googling "tkinter scroll canvas with widgets inside grid" – j_4321 Nov 19 '19 at 13:53

1 Answers1

0
import tkinter
window = tkinter.Tk()
window.title("scroll")
frame1 = tkinter.Frame(window)
frame1.grid()
bar = tkinter.Scrollbar(frame1, orient="vertical")
bar.grid(column=6, row=0, sticky="ns")
canvas = tkinter.Canvas(frame1, width=700, height=700, scrollregion=(2, 2, 1000, 1000), yscrollcommand=bar.set)
canvas.grid(column=0, row=0, sticky="nsew")
canvas.config(scrollregion=canvas.bbox("all"))
bar.config(command=canvas.yview)
frame = tkinter.Frame(canvas)
frame.grid()
canvas.create_window((0, 0), window=frame, anchor="nw")

# widgets come in here

window.mainloop()
Dan
  • 1
  • 4