This works fine when the listbox is root, however when I move it to a Toplevel window the scrollbar no longer appears.
Here is the specific code (Note the aassign query has not been applied)
class App:
def __init__(self):
self.listb=Toplevel()
self.listb.transient(root)
self.listb.title=('DB View')
self.vsb = Scrollbar(orient="vertical", command=self.OnVsb)
self.listNum = Listbox(self.listb, yscrollcommand=self.vsb.set)
self.listRoster = Listbox(self.listb, yscrollcommand=self.vsb.set)
self.vsb.pack(side="right",fill="y")
self.listNum.pack(side="left",fill="x", expand=True)
self.listRoster.pack(side="left",fill="x", expand=True)
self.listNum.bind("<MouseWheel>", self.OnMouseWheel)
self.listRoster.bind("<MouseWheel>", self.OnMouseWheel)
dbi = mdb.connect("localhost", port=3306, user="user", passwd="access", db="interactive_db")
cursor = dbi.cursor()
cursor.execute("""SELECT num FROM active_roster""")
rows = cursor.fetchall()
cursor.execute("""SELECT firstname, surname, assign FROM active_roster""")
staff =cursor.fetchall()
cursor.execute("""SELECT assign FROM active_assign""")
aassign = cursor.fetchall()
dbi.close()
print(rows)
print(aassign)
print (staff)
for results in rows:
self.listNum.insert("end", results)
for results2 in staff:
self.listRoster.insert("end", results2)
self.listb.mainloop()
def OnVsb(self, *args):
self.listNum.yview(*args)
self.listRoster.yview(*args)
def OnMouseWheel(self, event):
self.listNum.yview("scroll", event.delta,"units")
self.listRoster.yview("scroll",event.delta,"units")
return "break"
root = Tk()
root.title("Main")
root.geometry("900x600")
app=App()
listb = MultipleScrollingListbox()
#PRE-DUAL COLUMN SYNTAX PRE-CLASS DEF
numLabel=Label(root, text="Num #")
numLabel.grid(row=0,column=0)
assLabel=Label(root, text="Assignment")
assLabel.grid(row=0,column=2)
num_input=StringVar()
num_input=Entry(root,textvariable=num_input)
num_input.grid(row=0,column=1)
ass_input=StringVar()
ass_input=Entry(root,textvariable=ass_input)
ass_input.grid(row=0,column=3)
rosterList=Listbox(root, height=6,width=65)
rosterList.grid(row=2, column=0, rowspan=9, columnspan=4)
rosterList.bind('<<ListboxSelect>>', on_selection)
commScroll=Scrollbar(root)
commScroll.grid(row=2, column=4, rowspan=9)
rosterList.configure(yscrollcommand=commScroll.set)
commScroll.configure(command=rosterList.yview)
root.mainloop()
I included my original original syntax before I needed to move to a multicolumn layout with the hope of maintaining the same look I started migrating to the Class def - things started to go new awry...
I am new to Tkinter and need some direction here as the OnVsb definition appears to be messing up.
You need to include the master widget in the Scrollbar call:
self.vsb = Scrollbar(self.listb, orient="vertical", command=self.OnVsb)
Otherwise it defaults to the first root, which is why it was working before.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.