MCPcopy Index your code
hub / github.com/Akascape/CTkCodeBox / AddLineNums

Class AddLineNums

CTkCodeBox/ctk_code_box.py:14–53  ·  view source on GitHub ↗

Class for adding line numbers in CTkTextbox using TkLineNumbers

Source from the content-addressed store, hash-verified

12from pygments.styles import get_style_by_name, get_all_styles
13
14class AddLineNums(TkLineNumbers):
15 """
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)
48 self.master._y_scrollbar.set(x,y)
49
50 def _set_appearance_mode(self, mode_string):
51 self.colors = (self.master._apply_appearance_mode(self.text_color),
52 self.master._apply_appearance_mode(self.fg_color))
53 self.set_colors()
54
55class CTkCodeBox(customtkinter.CTkTextbox):
56 """

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected