| 16 | Class for adding line numbers in CTkTextbox using TkLineNumbers |
| 17 | """ |
| 18 | def __init__(self, |
| 19 | master, |
| 20 | text_color=None, |
| 21 | justify="left", |
| 22 | padx=30, |
| 23 | **kwargs): |
| 24 | |
| 25 | self.master = master |
| 26 | self.text_color = self.master.cget("border_color") if text_color is None else text_color |
| 27 | self.fg_color = self.master.cget("fg_color") |
| 28 | |
| 29 | customtkinter.windows.widgets.appearance_mode.CTkAppearanceModeBaseClass.__init__(self) |
| 30 | |
| 31 | super().__init__(self.master, self.master, justify=justify, |
| 32 | colors=(self.master._apply_appearance_mode(self.text_color), |
| 33 | self.master._apply_appearance_mode(self.fg_color)), |
| 34 | relief="flat", height=self.master.winfo_reqheight(), **kwargs) |
| 35 | |
| 36 | padding = self.master.cget("border_width") + self.master.cget("corner_radius") |
| 37 | |
| 38 | super().grid(row=0, column=0, sticky="nsw", padx=(padding,0), pady=padding-1) |
| 39 | |
| 40 | self.master._textbox.grid_configure(padx=(padx, 0)) |
| 41 | self.master._textbox.lift() |
| 42 | self.master._textbox.configure(yscrollcommand=self.set_scrollbar) |
| 43 | self.master._textbox.bind("<<ContentChanged>>", self.redraw, add=True) |
| 44 | self.master.bind("<Key>", lambda e: self.after(10, self.redraw), add=True) |
| 45 | |
| 46 | def set_scrollbar(self, x,y): |
| 47 | self.redraw(x,y) |