[Tkinter-discuss] Text and newlines [newbie Q]

spooky.ln at tbs-software.com spooky.ln at tbs-software.com
Tue Jan 4 00:22:25 CET 2011


hi,
after few&more trying i changed example to this working:

import re
from tkinter import *
from tkinter.font import Font

def get_current_line():
    start = text.index('insert linestart')
    end   = text.index('insert')
    return text.get(start, end)

def parse(event=None):
    line = get_current_line()
    match = re.search(reg, line)
    if match:
        print('match!', match.group('defkey'))
        text.insert('insert lineend', '\n')                   # changed
        text.insert('insert', '\t')                                 # +
    return 'break'                                                    # this 
was my problem i think

root=Tk()
f = Font(family='courier', size=-12)
text = Text(root, font=f, tabs=(4 * f.measure(0), 'left'),
tabstyle='wordprocessor')
text.pack(fill=BOTH, expand=1)
text.bind('<Return>', parse)
text.focus()
pattern  = r"^.*define\s(?P<defkey>.*):$"
reg = re.compile(pattern, re.S|re.M)

root.mainloop() 



More information about the Tkinter-discuss mailing list