Jeff
Jeff

Reputation: 161

python scroll workaround

I tend to use labels for everything text-related in my python programs. After coding a very long label for about 50 references, I'm now stuck with a toplevel window with a multiple line label, requiring a scrollbar, and labels don't scroll.

I've got the scrollbar on the window, but it doesn't scroll. Is there a workaround to scroll up and down my 'text' label or do I need a different widget to put in my toplevel window?

        filewin = Toplevel(background="white")

        scrollbar=Scrollbar(filewin)
        scrollbar.pack(side=RIGHT, fill=Y)
        yscrollcommand=scrollbar.set 


        Label(filewin, text=". . .\n \
    Acidophilium \n\
            Wichlacz,P.L., Unz,R.F., Langworthy,T.A. 1986. Acidiphilium angustum sp. nov. Acidiphilium facilis sp. nov. and Acidiphilium vubrum sp. nov. : \n\
                Acidophilic Heterotrophic Bacteria Isolated from Acidic Coal Mine Drainage. Int J Syst Bacteriol 36:197-201. \n\
    Acinetobacter \n\
            Bouvet,P.J.M., Grimont,P.A.D. 1986. Taxonomy of the Genus Acinetobacter with the Recognition of Acinetobacter baumannii sp. nov. Acinetobacter haemolyticus sp. \n\
                nov. Acinetobacter johnsonii sp. nov. and Acinetobacter junii sp. nov. and Emended Descriptions of Acinetobacter calcoaceticus and Acinetobacter lwofii. \n\
                Int J Syst Bacteriol 36:228-240.",
        justify=LEFT, background="white", foreground="black", wraplength=1000).pack()
        filewin.title("Matrix References")

Upvotes: 3

Views: 450

Answers (1)

joaquin
joaquin

Reputation: 85603

You can not use a scrollbar with a label.
Use Text instead:

from Tkinter import *

root = Tk()

mytext = "Here_your very long text"

scrbar = Scrollbar(root, orient=VERTICAL)
scrbar.pack(side=RIGHT,fill=Y)

text = Text(root, width=80, height=10, state=NORMAL, background="white", foreground="black")
text.insert(INSERT, mytext)
text['state'] = DISABLED
text.pack()

text['yscrollcommand'] = scrbar.set
scrbar['command'] = text.yview

root.title("Matrix References")
root.mainloop()

This produces (You should maybe adapt the text format):

enter image description here

Upvotes: 3

Related Questions