我是Python的新手,我正在为uni项目的聊天客户端开发一些基本图形。大多数事情似乎都可以正常工作,但是尽管对该问题进行了广泛的搜索,但我仍无法使滚动条正常工作。
chat = Tk()
chat.title('')
###
canvas = Canvas(chat, width = 450, height = 750)
scrollbar = Scrollbar(canvas, command = canvas.yview)
canvas.configure(yscrollcommand=scrollbar.set)
canvas.pack()
scrollbar.pack(side=RIGHT, fill=Y)
topframe = Frame(canvas, bg = 'dark slate blue', width = 450, height = 750)
topframe.pack(side = TOP)
topframe.propagate(0)
botframe = Frame(chat, bg = 'dark slate blue', width = 450, height = 50)
botframe.pack(side = BOTTOM)
###
my_msg = StringVar()
my_msg.set('Message...')
entrybox = Entry(botframe, textvariable=my_msg, bg='slate blue', width=47,
font = 'SansSerif 12')
entrybox.pack(side=LEFT)
sendbutton = Button(botframe, text = 'Send', width = 4, height = 1,
bg = 'gray11', fg = 'white', command = sendmsg)
sendbutton.pack(side=RIGHT)
entrybox.bind('<Return>',enter_pressed)
entrybox.bind('<Button-1>',clearentry)
chat.mainloop()
基本上,我在画布上有一个框架。所有消息都显示为框架内的“消息”小部件,但是一旦消息到达屏幕末端,我显然希望能够向下滚动。我的滚动条显示为灰色,无法与之交互。我发现有人提到了额外的canvas.configure语句,但是我也无法使其正常工作。我在做什么错了?