Feb-28-2019, 06:17 PM
Hello, please how can I select all the text in Text Wigdet just like that on Microsoft windows Notepad without including unnecessarily space on the right hand side for each line in the widget. Sorry just in case you don't get me, please try opening Notepad on windows Os and try to select all the text in it.
Thanks.
Thanks.
from tkinter import * from tkinter import ttk class Notepad: def __init__(self): self.master = Tk() self.master.build_Notepad() self.master.mainloop() def build_Notepad(self): self.frame_2 = ttk.Frame(self.master) self.frame_2.pack(fill=BOTH, expand=True) self.scrollbar = ttk.Scrollbar(self.frame_2) self.scrollbar.pack(side=RIGHT, fill=Y, expand=False) self.scrollbar_2 = ttk.Scrollbar(self.master, orient=HORIZONTAL) self.scrollbar_2.pack(fill=X, expand=NO) self.text = Text(self.frame_2,yscrollcommand=self.scrollbar.set,xscrollcommand=self.scrollbar_2.set,wrap=NONE,undo=True) self.text.pack(side=LEFT,fill=BOTH,expand=True) self.text.bind('<Button-3>',self.select_all_text) self.scrollbar.configure(command=self.text.yview) self.scrollbar_2.configure(command=self.text.xview) self.text.insert(INSERT,'Select every text now') def select_all_text(self,event=None): self.text.tag_configure('sel',background='#8A2BE2') for self.line in self.text.get('1.0','end-1c').splitlines(): self.line = self.text self.line.tag_add(SEL,'insert linestart','insert lineend') self.line.mark_set(INSERT,'1.0') self.line.see(INSERT) return 'break' if __name__ == '__main__': Notepad()