tkinter Text editor lines counter -
*i not @ english. please understand awkward english.
hello!
i making text editor.
but, want more perfect...
so want making text line counter. look:
what can use feature?
class main: def __init__(self,master): (skip) self.__class__.editors.append(self) self.linenumbers = '' self.frame = frame(master, bd=2, relief=sunken) self.lntext = text(self.frame, width = 4, padx = 4, highlightthickness = 0, takefocus = 0, bd = 0, background = 'lightgrey', foreground = 'magenta', state='disabled' ) self.lntext.pack(side=left, fill='y') if self.__class__.updateid none: self.updatealllinenumbers() def getlinenumbers(self): x = 0 line = '0' col= '' ln = '' # assume each line @ least 6 pixels high step = 6 nl = '\n' linemask = ' %s\n' indexmask = '@0,%d' in range(0, self.editor.winfo_height, step): ll, cc = self.editor.index( indexmask % i).split('.') if line == ll: if col != cc: col = cc ln += nl else: line, col = ll, cc ln += (linemask % line)[-5:] return ln def updatelinenumbers(self): tt = self.lntext ln = self.getlinenumbers() if self.linenumbers != ln: self.linenumbers = ln tt.config(state='normal') tt.delete('1.0', end) tt.insert('1.0', self.linenumbers) tt.config(state='disabled') @classmethod def updatealllinenumbers(cls): if len(cls.editors) < 1: cls.updateid = none return ed in cls.editors: ed.updatelinenumbers() cls.updateid = ed.text.after( cls.update_period, cls.updatealllinenumbers)
full source code download -> http://blog.naver.com/tdh8316/220854695216
this code has encountered error.
error message is
... traceback (most recent call last): file "g:\_#project\_editor\py\textmate\textmate\textmate.py", line 547, in <module> runmainwindow() # run mainwindow class file "g:\_#project\_editor\py\textmate\textmate\textmate.py", line 543, in runmainwindow app = mainwindow(root) file "g:\_#project\_editor\py\textmate\textmate\textmate.py", line 68, in __init__ self.updatealllinenumbers() file "g:\_#project\_editor\py\textmate\textmate\textmate.py", line 532, in updatealllinenumbers ed.updatelinenumbers() file "g:\_#project\_editor\py\textmate\textmate\textmate.py", line 516, in updatelinenumbers ln = self.getlinenumbers() file "g:\_#project\_editor\py\textmate\textmate\textmate.py", line 499, in getlinenumbers in range(0, self.editor.winfo_height, step): typeerror: 'method' object cannot interpreted integer
why error causes?
what 'method object'?
i can't speak english well. sorry, thank you
you can create text
widget, pack on left
fill = y
. here example code :
...#some stuff above including text linetext = text() linetext.config(state = disabled) #we need make sure scrollbar on text widget scrolls linetext def configscroll(*args): textblock.yview(*args) linetext.yview(*args) scrollbaronyourtextwidget.config(command = configscroll) def updatelinenumber(): endoftext = int(textblock.index("end").split(".")[0]) #get need stop in range(1, endoftext + 1): linetext.config(state = normal) linetext.insert(end, i) linetext.config(state = disabled) #config width of linetext linetext.config(width = len(endoftext) + 2) #just formula found :) #next need make sure when type, linetext follows textblock.mark_set("textmark", endoftext) #scroll spot textblock.see("textmark") textblock.bind("<any-key>", updatelinenumber)
Comments
Post a Comment