Python 我在tkinter中设置的可滚动画布有什么问题?

Python 我在tkinter中设置的可滚动画布有什么问题?,python,tkinter,Python,Tkinter,我正在尝试使用tkinter设置可滚动画布: from tkinter import * class PopupTk(Frame): def __init__(self, master=None, title="Notification", msg="New information", duration=2): Frame.__init__(self, master) self.duration = duration # setup b

我正在尝试使用tkinter设置可滚动画布:

from tkinter import *

class PopupTk(Frame):
    def __init__(self, master=None, title="Notification", msg="New information", duration=2):
        Frame.__init__(self, master)
        self.duration = duration

        # setup button
        close_button = Button(self, text="C", command=self.master.destroy)
        close_button.pack(side=LEFT)

        # set up scrollable canvas
        vscrollbar = Scrollbar(self, orient=VERTICAL)
        # vscrollbar.pack(fill=Y, side=RIGHT, expand=FALSE)
        vscrollbar.pack(side=LEFT)
        canvas = Canvas(self, bd=0, highlightthickness=0, yscrollcommand=vscrollbar.set)
        # canvas.pack(fill=BOTH, expand=TRUE)
        canvas.pack(side=LEFT)
        vscrollbar.config(command=canvas.yview)


        # setup text inside canvas
        title_label = Label(canvas, text=title, wraplength=250)
        title_label.config(justify=LEFT)
        title_label.pack(fill=X)
        msg_label = Label(canvas, text=msg, wraplength=250)
        msg_label.config(justify=LEFT)
        msg_label.pack(fill=X)

        self.pack(side=TOP, fill=BOTH, expand=YES, padx=10, pady=10)

        # get screen width and height
        ws = self.master.winfo_screenwidth()
        hs = self.master.winfo_screenheight()
        w = 300
        h = 100
        # calculate position x, y
        x = ws - w
        y = hs - h
        self.master.geometry('%dx%d+%d+%d' % (w, h, x, y))
        self.master.overrideredirect(True)
        self.master.lift()

    def auto_close(self):
        msec_until_close = self.duration * 1000
        self.master.after(msec_until_close, self.master.destroy)


if __name__ == '__main__':
    root = Tk()

    sp = PopupTk(root, msg="If you don’t specify a size, the label is made just large enough to hold its contents. If you don’t specify a size, the label is made just large enough to hold its contents. ", duration=33)
    sp.auto_close()
    root.call('wm', 'attributes', '.', '-topmost', True)
    root.mainloop()
但滚动条根本不起作用,甚至不太可见:


滚动条在打包到画布中的小部件上不起作用。它只会滚动添加了创建窗口的小部件。

请给出一个小例子好吗?谢谢这些问题都有示例的答案:,