I'm creating line numbers in my notepad app and I'm trying to get the line numbers text widget and the one where you enter text into to scroll with each other. Currently I have gotten the scroll bar part working. Its the mouse wheel that's giving me issues. I cant seem to get the mouse wheel par to work right.
Code for scroll:
def _on_mousewheel(event):
my_text.yview_scroll.int(-1*(event.delta/120), "units")
def _bound_to_mousewheel(event):
root.bind_all("<MouseWheel>", _on_mousewheel)
def _bound_to_mousewheel(self, event):
self.root.bind_all("<MouseWheel>", self._on_mousewheel)
my_frame = Frame(root, background="#2A2F31")
my_frame.pack(pady=5, fill=BOTH, expand=True)
my_frame.bind('<Enter>', _bound_to_mousewheel)
text_scroll = Scrollbar(my_frame)
text_scroll.pack(side=RIGHT, fill=Y)
text_scroll2 = Scrollbar(my_frame, orient='horizontal')
text_scroll2.pack(side=BOTTOM, fill=X)
lines = Text(my_frame, width= 5, borderwidth = '0', font=("Helvetica", 16), yscrollcommand=text_scroll.set, fg="WHITE", bg="#2f3136", wrap='none', undo=True)
lines.pack(side=LEFT, fill=Y)
lines.config(state='disabled')
my_text = Text(my_frame, font=("Helvetica", 16), selectbackground="Light Blue", selectforeground="Black", undo=True, yscrollcommand=text_scroll.set, bg="#2f3136", fg="WHITE", wrap='none', xscrollcommand=text_scroll2.set, borderwidth = '0')
my_text.pack(fill=BOTH, expand=True)
text_scroll.config(command=scroll)
text_scroll2.config(command=my_text.xview)
With the code here, there are no errors in the console but also nothing happens. Ive looked at other similar questions but they weren't much help. I could not get them implamented into my code. Could someone help me with this.