-1

I'm continuing work on a translation/dictionary app to translate English words to my native language. I want to insert a vertical scrollbar on the output widget so that users can scroll up and down to see overflow content. Please, how do I do this? Thanks.

Below is the code:

from tkinter import *
root=Tk()
root.geometry('250x250')
root.configure(background="#35424a")

#Entry widget object
textin = StringVar()

def clk():
    entered = ent.get().lower() #get user input and convert to lowercase
    output.delete(0.0,END)
    if len(entered) > 0:
        try:
            textin = exlist[entered]
        except:
            textin = 'Word not found'
        output.insert(0.0,textin)

#Entry field
ent=Entry(root,width=15,font=('Times 18'),textvar=textin,bg='white')
ent.place(x=30,y=15)

#Search button
but=Button(root,padx=1,pady=1,text='Translate',command=clk,bg='powder blue',font=('none 18 
bold'))
but.place(x=60,y=60)

#output field
output=Text(root,width=15,height=4,font=('Times 18'),fg="black")
output.place(x=30,y=120)

#prevent sizing of window
root.resizable(False,False) 

#Dictionary
exlist={
    "drum":"drum: (with skin) ŋgɔ̀m; (long, single-headed, skin-covered) ɨbûm ŋgɔ̀m; (with one 
end) ŋgɔ̀m ə̀tu", 
    "bag":"bag: (n) ə̀bàmɨ̀ pl. ɨ̀bàmɨ̀; (assp) (fibre bag) ə̀bàmɨ̀ tɨswé; (a type of bag made of 
animal skin) ndoŋ",
    "ant":"ant: ɨgwírɨ́ (pl. əgwirɨ); (has a big croup) ɨgwírɨ́ ndiŋ; (ant species, very 
small, attack and destroy white ants)"
    }

root.mainloop()

enter image description here

Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
DTambah
  • 69
  • 8
  • 1
    There are two excellent implementations here: https://stackoverflow.com/a/13833338/2237151 – Pietro Mar 15 '21 at 10:19
  • 1
    It seems like you can answer this question by reading available documentation or looking at one of countless examples on the internet. It's not clear what problem you're having since your code doesn't even try to add a scrollbar. – Bryan Oakley Mar 15 '21 at 14:29
  • Ok. I'll keep trying; where I'm stuck I'll fall back – DTambah Mar 15 '21 at 17:59

1 Answers1

1

What you need is a scrollable text widget, tkinter has it built in too. You need to use tkinter.scrolledtext.ScrolledText. So just change your Text widget to:

from tkinter import scrolledtext
# Rest of your code

output = scrolledtext.ScrolledText(root,width=15,height=4,font=('Times 18'),fg="black")
output.place(x=30,y=120)
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46