I am working on a project with my friend. We are using 16 listboxes. We made a progam to scroll all of them at the same time, but the problem is that it took us around 300 lines of code and we want to tidy it up but we dont know how to do it. We made a little prototype, but we cant figure out how to stop listbox from scrolling more than other because of hovering over it. Can someone tell us how to do that?
from tkinter import *
screen = Tk()
screen.title("EEPROM programmer")
screen.geometry("1050x620")
screen.maxsize(width = 1050, height = 620)
screen.minsize(width = 1050, height = 620)
listBoxes = {}
listNumber = 16
scrollbar = Scrollbar(screen)
scrollbar.place(x=25*17,y=25,height=100)
scrollPosition = 0
print(len(listBoxes))
def scrolllist(event):
global scrollPosition
scrollPosition += (((-event.delta)/120)*7)/75
if scrollPosition >= 0.75:
scrollPosition = 0.75
elif scrollPosition <= 0:
scrollPosition = 0
print(scrollPosition)
for num in range(listNumber):
listBoxes[num].yview("moveto", scrollPosition)
print()
for x in range(listNumber):
listBoxes[x] = Listbox(screen, font=("consolas", 12, "bold"), height=25, width=3, yscrollcommand=scrollbar.set)
listBoxes[x].place(x=25*x, y=25)
listBoxes[x].bind("<MouseWheel>", scrolllist)
for y in range(100):
for x in range(listNumber):
listBoxes[x].insert(0, y)
def scrollLists(x, y):
print(x)
print(y)
global scrollPosition
scrollPosition = float(y)
for num in range(listNumber):
listBoxes[num].yview(x, y)
scrollbar.config(command = scrollLists)
screen.mainloop()