Текст ОТКЛЮЧЕН, но полосу прокрутки оставьте НОРМАЛЬНОЙPython

Программы на Python
Anonymous
Текст ОТКЛЮЧЕН, но полосу прокрутки оставьте НОРМАЛЬНОЙ

Сообщение Anonymous »

Кажется, я не могу найти решение этой проблемы. Если у меня есть текстовое поле, для которого я указал = DISABLE, оно также отключает полосу прокрутки.
Есть ли способ обойти это?

Код: Выделить всё

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('', text_to_textbox)

win.mainloop()
Я искал на форумах, но нашел только советы по отключению текста и полосы прокрутки.

Подробнее здесь: https://stackoverflow.com/questions/787 ... bar-normal

Вернуться в «Python»