我正在尝试向此列表框小部件添加滚动条,但是尽管出现了画布,但其中没有任何可交互的对象。这是屏幕截图:
我的代码如下:
def readMessage(userhash):
def readMsgs(message):
readWin = Tk()
msg = Message(readWin, width=200, text=message).grid(padx=5, pady=5)
endBtn = Button(readWin, text='Close', command=lambda: readWin.state("withdrawn")).grid(padx=5, pady=5)
readMsgsWin = Tk()
scrollbar = ttk.Scrollbar(readMsgsWin)
scrollbar.grid(row=1, column=2, sticky='ns')
msgListbox = Listbox(readMsgsWin, width=35, yscrollcommand=scrollbar.set)
msgsDict = literal_eval(sendStr(str(['findMsgs', str(userhash)]), 5000))
scrollbar.config(command=msgListbox.yview)
print (msgsDict, type(msgsDict))
for key, message in msgsDict.items():
msgsDict[key] = decrypt(message)
msgListbox.insert(END, key)
readBtn = Button(readMsgsWin, text='Read', command=lambda: readMsgs(msgsDict[msgListbox.get(msgListbox.curselection())]))
closeBtn = Button(readMsgsWin, text='Close', command=lambda: readMsgsWin.state("withdrawn"))
msgListbox.grid(row=1, column=1, padx=5, pady=5)
readBtn.grid(row=2, column=1, padx=5, pady=5)
closeBtn.grid(row=2, column=2, padx=5, pady=5)
请帮助,尝试了许多网站示例后,我的想法已经用尽,将它们集成到程序中后,这些示例都没有用。我以前从未尝试过在tkinter中实现滚动条。