[英]Loose yScroll when move Listbox Class to Toplevel from ROOT - in Tkinter
當列表框為根目錄時,此方法運行良好,但是當我將其移至“頂級”窗口時,滾動條將不再出現。
這是特定的代碼(請注意,尚未應用aassign查詢)
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()
在需要移動到多列布局之前,我已經包含了原始的原始語法,希望保持與開始遷移到Class def時相同的外觀-事情開始出現新的錯誤...
我是Tkinter的新手,在這里需要一些指導,因為OnVsb定義似乎很混亂。
您需要在滾動條調用中包含主窗口小部件:
self.vsb = Scrollbar(self.listb, orient="vertical", command=self.OnVsb)
否則,它默認為第一個根,這就是它以前運行的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.