0

snippets of my codes are attached.

import tkinter
from tkinter import *

root = tkinter.Tk()
root.geometry("1500x900")
root.title("ddw")

frame = tkinter.Frame(root)
#frame.grid(row=0,column=0,padx=20,pady=10)

frame.pack(fill="both", expand=True)
scrollbar = Scrollbar(frame)
scrollbar.pack(side="left",fill="y")

ls = [(x+1)*5 for x in range(10)]

for x in ls:

    cnn_info_frame = tkinter.LabelFrame(frame, text="cn")
    cnn_info_frame.grid(row=x, column=0, padx=20, pady=10)

    vv1_label = tkinter.Label(cnn_info_frame, text="vv1")
    vv1_label.grid(row=0, column=0)
    vv2_label = tkinter.Label(cnn_info_frame, text="vv2")
    vv2_label.grid(row=1, column=0)
    vv3_label = tkinter.Label(cnn_info_frame, text="vv3")
    vv3_label.grid(row=2, column=0)

    vv1_entry = tkinter.Entry(cnn_info_frame)
    vv2_entry = tkinter.Entry(cnn_info_frame)
    vv3_entry = tkinter.Entry(cnn_info_frame)

    vv1_entry.grid(row=0, column=1, padx=5, pady=5)
    vv2_entry.grid(row=1, column=1, padx=5, pady=5)
    vv3_entry.grid(row=2, column=1, padx=5, pady=5)



root.mainloop()

I am really new to tkinter and tech is not my background so any help is most appreciated. I want to create a scroll bar on the left so I added

scrollbar = Scrollbar(frame)
scrollbar.pack(side="left",fill="y")

but that gives me this error

Traceback (most recent call last):
  File "C:/Users/kamathp/PycharmProjects/CFOptimisation/00tkinter_eg4.py", line 20, in <module>
    cnn_info_frame.grid(row=x, column=0, padx=20, pady=10)
  File "C:\Users\kamathp\Anaconda3\envs\PA36\lib\tkinter\__init__.py", line 2226, in grid_configure
    + self._options(cnf, kw))
_tkinter.TclError: cannot use geometry manager grid inside .!frame which already has slaves managed by pack

how do I fix it? My actually code has a lot of labelFrames button etc, but my main issue not able to add the scroll bar to the left.

TRex
  • 445
  • 5
  • 14
  • Either changing `scrollbar` to use `grid()` or `cnn_info_frame` to use `pack()`. – acw1668 May 15 '23 at 11:55
  • thanks @acw1668. I added - scrollbar.grid(row=0,column=0,padx=10,pady=10). I can see the scrollbar but its very small and at the top left, and doesnt look like its working? – TRex May 15 '23 at 12:36
  • A frame does not support scrolling, so why do you think that the scrollbar works for your case? – acw1668 May 15 '23 at 13:17
  • 2
    Tkinter has no scrollable Frames but you can make your own with tk.Canvas and add a frame to the canvas. Then you make the canvas scrollable. – Module_art May 15 '23 at 13:29
  • 1
    I asked a similar question it might help you [How to resize Canvas scrollable widget?](https://stackoverflow.com/questions/67860815/how-to-resize-canvas-scrollable-widget) – Module_art May 15 '23 at 13:38
  • 1
    @Module_art thank you that was helpful. I now have that works well – TRex May 15 '23 at 13:40
  • 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 May 20 '23 at 09:50

0 Answers0