Code

tiforadacaixa

CURSO DE TKINTER AULA #15 - texto com scroll lateral - text area

15- texto com scroll lateral - text area

Para adicionar uma caixa de texto com scroll, vocĂȘ pode usar a classe ScrolledText dessa forma:

#importamos a classe: from tkinter import scrolledtext #e a instanciamos texto=scrolledtext.ScrolledText(window,width=20,height=5)

Exeplo de uso:

from tkinter import * from tkinter import scrolledtext from tkinter.ttk import * window = Tk() window.geometry("300x200+200+100") window.title("TI fora da caixa") texto = scrolledtext.ScrolledText(window,width=20,height=5) texto.pack() window.mainloop()

E o resultado sera esse:

###############################################################

15.1-Inserir texto na textbox / Input:


Para adicionar um texto em uma textbox podemos usar a função insert:


texto.insert(INSERT, "TEXTO DE EXEMPLO")


Exemplo de uso:



from tkinter import * from tkinter import scrolledtext from tkinter.ttk import * window = Tk() window.geometry("300x200+200+100") window.title("TI fora da caixa") texto = scrolledtext.ScrolledText(window,width=20,height=5) texto.insert(INSERT, "TEXTO DE EXEMPLO") texto.pack() window.mainloop()

E o resultado sera esse:
###############################################################

15.2-Limpar TextBox / Input:


Para excluir todo o texto de uma textbox podemos usar a função delete(), exemplo de uso:


texto.delete(1.0, END)


Exemplo de uso:


from tkinter import * from tkinter import scrolledtext from tkinter.ttk import * def limparTextbox():     texto.delete(1.0,END)      window = Tk() window.geometry("300x200+200+100") window.title("TI fora da caixa") texto = scrolledtext.ScrolledText(window,width=20,height=5) texto.pack() texto.insert(INSERT, "TEXTO DE EXEMPLO") bt=Button(window, text="Limpar", command=limparTextbox) bt.pack() window.mainloop()



E ao executar esse cĂłdigo obtemos o seguinte resultado:

Postar um comentĂĄrio

2 ComentĂĄrios

  1. Respostas
    1. tive uns problemas com aquele layout, os códigos estavam ficando com erros de identação.

      Excluir