|
1 | 1 | import tkinter as tk |
2 | | -from tkinter import filedialog |
3 | | - |
| 2 | +from tkinter import filedialog, Text, Menu |
4 | 3 |
|
5 | 4 | # Main Window |
6 | 5 |
|
@@ -124,12 +123,49 @@ def open_find_replace_dialog(): |
124 | 123 | dialog = FindReplaceDialog(root) |
125 | 124 | root.wait_window(dialog) # This will wait until the dialog window is closed. |
126 | 125 |
|
127 | | - |
128 | | -# Define the add-shortcut function |
129 | | - |
130 | 126 | def add_shortcut(key, func): |
131 | 127 | root.bind(key, lambda event: func()) |
132 | 128 |
|
| 129 | + |
| 130 | +#### Dark Mode Feature #### |
| 131 | + |
| 132 | +# Color schemes |
| 133 | +light_mode = { |
| 134 | + "text_bg": "#FFFFFF", # White background for the text area |
| 135 | + "text_fg": "#000000", # Black text color |
| 136 | + "sidebar_bg": "#F0F0F0", # Light background for line numbers |
| 137 | + "sidebar_fg": "#000000", # Black color for line numbers |
| 138 | + "menu_bg": "#F0F0F0", # Light background for the menu |
| 139 | + "menu_fg": "#000000", # Black text color for the menu |
| 140 | +} |
| 141 | + |
| 142 | +dark_mode = { |
| 143 | + "text_bg": "#333333", # Dark background for the text area |
| 144 | + "text_fg": "#CCCCCC", # Light grey text color |
| 145 | + "sidebar_bg": "#1E1E1E", # Dark background for line numbers |
| 146 | + "sidebar_fg": "#FFFFFF", # White color for line numbers |
| 147 | + "menu_bg": "#1E1E1E", # Dark background for the menu |
| 148 | + "menu_fg": "#CCCCCC", # Light grey text color for the menu |
| 149 | +} |
| 150 | + |
| 151 | +# Current mode starts as light mode |
| 152 | +current_mode = "light" |
| 153 | + |
| 154 | +def toggle_dark_mode(): |
| 155 | + global current_mode |
| 156 | + # Toggle between 'light' and 'dark' |
| 157 | + current_mode = 'dark' if current_mode == 'light' else 'light' |
| 158 | + color_scheme = dark_mode if current_mode == 'dark' else light_mode |
| 159 | + |
| 160 | + # Apply color scheme to text widget and line numbers |
| 161 | + text.config(bg=color_scheme["text_bg"], fg=color_scheme["text_fg"], insertbackground=color_scheme["text_fg"]) |
| 162 | + line_numbers.config(bg=color_scheme["sidebar_bg"], fg=color_scheme["sidebar_fg"]) |
| 163 | + |
| 164 | + # Update the colors for the menu and all of its children |
| 165 | + menu.config(bg=color_scheme["menu_bg"], fg=color_scheme["menu_fg"]) |
| 166 | + for menu_item in menu.winfo_children(): |
| 167 | + menu_item.config(bg=color_scheme["menu_bg"], fg=color_scheme["menu_fg"]) |
| 168 | + |
133 | 169 | # Bind shortcuts to these functions |
134 | 170 |
|
135 | 171 | add_shortcut('<Control-n>', new_file) |
@@ -175,6 +211,12 @@ def add_shortcut(key, func): |
175 | 211 | edit_menu.add_command(label="Select All", command=select_all, accelerator="Ctrl+A") |
176 | 212 | edit_menu.add_command(label="Find and Replace", command=open_find_replace_dialog, accelerator="Ctrl+F") |
177 | 213 |
|
| 214 | +# View Menu |
| 215 | + |
| 216 | +view_menu = tk.Menu(menu, tearoff=0) |
| 217 | +menu.add_cascade(label="View", menu=view_menu) |
| 218 | +view_menu.add_command(label="Toggle Dark Mode", command=toggle_dark_mode) |
| 219 | + |
178 | 220 | # Line Numbers |
179 | 221 | line_numbers = LineNumberCanvas(root, width=30) |
180 | 222 | line_numbers.pack(side="left", fill="y") |
|
0 commit comments