python3 Tkinter scrollbar problems to insert

Asked

Viewed 117 times

0

good morning,

I was creating a graphical interface with python and for that I used Tkinter and I was trying to create a scrollbar inside my project but it does not recognize the command to connect to scroolbar the existing labels (follow the example):

from tkinter import *

class JanelaPrincipal(Frame):
        def __init__(self,master):
                Frame.__init__(self,master)
                self.master.title('Avocado')
                self.master.geometry('800x600')
                self.configure(height=200,width=200)
                #scroll bar
                self.scroll=Scrollbar(master)
                self.scroll.pack(side=RIGHT, fill="y")
                self.batata=Label(self.master,width="800",height="10",text="Algum texto",relief="raise",yscrollcommand=self.scroll.set)
                self.batata.pack(expand=0, fill=BOTH, side=TOP)

root=Tk()
app=JanelaPrincipal(root)
root.mainloop()

The error that returns is:

Traceback (most recent call last):
  File "pap.py", line 16, in <module>
    app=JanelaPrincipal(root)
  File "pap.py", line 12, in __init__
    self.batata=Label(self.master,width="800",height="10",text="Algum texto",relief="raise",yscrollcommand=self.scroll.set)
  File "/usr/lib/python3.6/tkinter/__init__.py", line 2766, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)
  File "/usr/lib/python3.6/tkinter/__init__.py", line 2299, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: unknown option "-yscrollcommand"

I’ve done enough research but everyone uses that argument and when I try to use the error interpreter, if anyone can help

1 answer

1


Turns out you’re trying to create a scroll in a Label and this class doesn’t have the option yscrollcommand.

You can use this property at Listbox, Canvas etc..

See an example of using it with the class Text, using your code as a basis:

from tkinter import *

class JanelaPrincipal(Frame):
    def __init__(self,master):
        Frame.__init__(self,master)
        self.master.title('Avocado')
        self.master.geometry('800x600')
        self.configure(height=200,width=200)
        #scroll bar
        self.scroll=Scrollbar(master)
        self.scroll.pack(side=RIGHT, fill="y")
        self.batata=Text(self.master,width=800,height=10,relief="raise",yscrollcommand=self.scroll.set)
        self.batata.insert(END, "Algum texto")
        self.batata.pack(expand=0, fill=BOTH, side=LEFT)

root=Tk()
app=JanelaPrincipal(root)
root.mainloop()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.