繁体   English   中英

在Tkinter中将列表框类从ROOT移到Toplevel时,yScroll松散

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM