Hello I can’t seem to find a solution to this one. If I have a Text box that I state=DISABLE, it also disables the scrollbar.
Is there a way around this?
from tkinter import *
from tkinter import ttk
#Create an instance of tkinter frame
win = Tk()
#Set the geometry of tkinter frame
win.geometry("480x550")
def text_to_textbox(*args) -> None: # *args as bind enter sends a position parameter!?
response = entry_box.get() # Get the text from the Entry box
text.config(state=NORMAL) # Enable the textbox so you can write to it
text.insert(END,f'n{response}') # New line then add text at the END of the text.
text.see('end') # Autoscroll
entry_box.delete(0, END)
text.config(state=DISABLED) # Delete the contents of the Entry box
textFrame = ttk.Frame(win, width=480, height=150)
textFrame.grid(row=0, column=0, padx=10, pady=10)
scrollbar = Scrollbar(textFrame)
text= Text(textFrame, width= 50, height= 20, background="gray71",foreground="#fff",font= ('Sans Serif', 13, 'italic bold'))
#Insert the text at the begining
text.insert(INSERT, "Hello, please Write Something...")
text.pack(expand= 1, fill= BOTH)
text.config(state=DISABLED) # Disable textbox so you can't write directly to it.
scrollbar.pack(side=RIGHT, fill=Y) # Add a scrollbar to the textbox down the right side
scrollbar.config(command=text.yview) # The scrollbar goes up and down (Y position)
responseFrame = ttk.Frame(win, width=750, height=50)
responseFrame.grid(row=1, column=0, padx=10, pady=10)
entry_box = Entry(responseFrame, width=50)
entry_box.grid(row=0, column=0, padx=5, pady=5, sticky='w')
entry_button = Button(responseFrame, text=' Send ', padx=5, pady=5)
entry_button.grid(row=0, column=1, padx=5, pady=5)
entry_button.config(command=text_to_textbox)
win.bind('<Return>', text_to_textbox)
win.mainloop()
I’ve searched forums but can only find advice on DISABLE’ing of Text and Scrollbar.your text
New contributor
Phil LuvsChips is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.