Feb-15-2020, 02:52 PM
hello everybody
I'm trying to create a simple text editor in Tkinter, to help building HTML pages.
I just write things in the text area, and use buttons to add tags, like <h1>.
![[Image: Captura-de-tela-de-2020-02-15-11-44-44.png]](https://i.postimg.cc/Jzdgtdzm/Captura-de-tela-de-2020-02-15-11-44-44.png)
this is what I have so far:
but currently I get this error when I press the button (the function addHeader is not working):
thanks in advance
I'm trying to create a simple text editor in Tkinter, to help building HTML pages.
I just write things in the text area, and use buttons to add tags, like <h1>.
![[Image: Captura-de-tela-de-2020-02-15-11-44-44.png]](https://i.postimg.cc/Jzdgtdzm/Captura-de-tela-de-2020-02-15-11-44-44.png)
this is what I have so far:
from tkinter import * root = Tk() def addHeader(): a = main_text.get(Tk.SEL_FIRST, Tk.SEL_LAST) main_text = Text(root).grid(row=0, column=0, rowspan=6) b_header = Button(root, text ="Header", command=addHeader).grid(row=0, column=1, padx=2, pady=2) spin_header = Spinbox(root, from_=1, to=6, width=5).grid(row=0, column=2, padx=2, pady=2) b_ref = Button(root, text ="Referência").grid(row=1, column=1, padx=2, pady=2) spin_href = Spinbox(root, from_=0, to=9999, width=5).grid(row=1, column=2, padx=2, pady=2) name_label = Label(root, text="Nome do Arquivo: ").grid(row=2, column=1, columnspan=2, padx=2, pady=2) name_entry = Entry(root).grid(row=3, column=1, columnspan=2, padx=2, pady=2) b_save = Button(root, text ="Finalizar e Salvar").grid(row=4, column=1, columnspan=2, padx=2, pady=2) root.mainloop()what I want to achieve is, when the b_header is pressed, html tags are added around whatever is selected in the text area (ie, add <h1> at the beggining of the selected text and </h1> at the end). if nothing is selected, just add the tags in the cursor position.
but currently I get this error when I press the button (the function addHeader is not working):
Error:Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "teste.py", line 5, in addHeader
a = main_text.get(Tk.SEL_FIRST, Tk.SEL_LAST)
AttributeError: 'NoneType' object has no attribute 'get'
any ideas on how to make it work?thanks in advance
