0

i keep trying to add vertical scrollbar to label frame in Tkinter, but i keep failing, is it even possible? I saw previous posts about this, but those posts are from more than 5 years ago, so i wanted to see if something changed. I created a function that adds new Entries when button is pressed, and I want to add a scrollbar so that I can see all entries in case there is a lot of them. Can you help me with this?

This is the error:

AttributeError: 'LabelFrame' object has no attribute 'yview'

This is my code:

from tkinter import *
from tkinter import ttk

myApp = Tk()
myApp.title(" MY GUI")                         
myApp.geometry("1000x650")


frame1=LabelFrame(myApp,text="Activities",height=15)
frame1.grid(row=0,column=0,padx=5)

vertSB=ttk.Scrollbar(frame1,orient="vertical",command=frame1.yview)
vertSB.grid(row=2,rowspan=10,column=6,padx=5,sticky="NS")
frame1.configure(yscrollcommand=vertSB.set)

i=Label(frame1, text=" i ")
i.grid(row=0,column=1,pady=5)

Tasks=Label(frame1, text="Tasks")
Tasks.grid(row=0,column=2,pady=5)

Planned=Label(frame1, text="Planned")
Planned.grid(row=0,column=3,pady=5)

Real=Label(frame1, text="Real")
Real.grid(row=0,column=4,pady=5)

Prod=Label(frame1, text="Prod.")
Prod.grid(row=0,column=5,pady=5)

newrow=1
class AddNewTask(object):
    rowlist=[]

    def update_row_values(self):

        for i,entry in enumerate(self.rowlist):
            entry.delete(0, 'end')
            entry.insert(0,i+1)

    def addTask(self):

        def delete():
            bdelete.destroy()
            iEntry.destroy()
            taskEntry.destroy()
            plannedEntry.destroy()
            realEntry.destroy()
            prodEntry.destroy()
            self.rowlist.remove(iEntry)
            self.update_row_values()

        global newrow
        newrow=newrow+1

        bdelete=Button(frame1,text="-",command=delete)
        bdelete.grid(row=newrow,column=0,sticky="E",padx=4)

        iEntry=Entry(frame1,width=3)    
        self.rowlist.append(iEntry)     
        iEntry.grid(row=newrow,column=1,padx=1)   
        n = len(self.rowlist)  
        iEntry.insert(0,n)  

        taskEntry=Entry(frame1,width=55)
        taskEntry.grid(row=newrow,column=2,padx=1)

        plannedEntry=Entry(frame1,width=11)
        plannedEntry.grid(row=newrow,column=3,padx=1)

        realEntry=Entry(frame1,width=11)
        realEntry.grid(row=newrow,column=4,padx=1)

        prodEntry=Entry(frame1,width=11)
        prodEntry.grid(row=newrow,column=5,padx=1)


    def __init__(self):

        buttonadd=Button(frame1,text="Add Task",command=self.addTask)
        buttonadd.grid(row=0,column=0,padx=3,pady=5)

AddNewTask=AddNewTask()

myApp.mainloop()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685

1 Answers1

0

No it is not possible to add a scrollbar to a LabelFrame. May I suggest the use of listbox.

ViG
  • 1,848
  • 1
  • 11
  • 13
  • Thanks, but listbox will not solve my problem. User needs to add values (a lot of them), and with that values he needs to get some results . –  Feb 06 '18 at 15:54
  • @Aleksandar You can also use the module `Pmw`, it has a widget `ScrolledFrame` – ViG Feb 06 '18 at 16:00