tkinter:滚动条出现但不起作用

时间:2017-02-19 00:50:36

标签: python python-3.x tkinter widget scrollbar

即使滚动条出现且可移动,它也不会滚动窗口中的文本。

我是tkinter的新手,我似乎无法找到问题。

这就是我的尝试:

def opensave():
    global openname
    if saveordelete == 1:
        openname = savedname.get() + ".txt"
        my_file = Path(openname)
        if my_file.is_file():
            file = open(openname, "r")
            readopenname = file.read()
            file.close()
            root = Tk()
            root.title("Saved file")
            root.iconbitmap("morseicon.ico")
            root.resizable(0,0)
            root.geometry("520x610")
            scrollbar = Scrollbar(root)
            scrollbar.pack( side = RIGHT, fill=Y )
            T = Listbox(root, yscrollcommand = scrollbar.set )
            scrollbar.config( command = T.yview )                      
            T = Text(root, height=500, width=500)
            T.pack()
            T.insert(END, readopenname)
            root.mainloop()

1 个答案:

答案 0 :(得分:1)

所以最终我设法解决了这个问题:

def opensave():
        global openname
        if saveordelete == 1:
            openname = savedname.get() + ".txt"
            my_file = Path(openname)
            if my_file.is_file():
                file = open(openname, "r")
                readopenname = file.read()
                file.close()
                root = Tk()
                root.title("Saved file")
                root.iconbitmap("morseicon.ico")
                root.geometry("520x610")
                root.resizable(0,0)
                scrollbar = Scrollbar(root)
                scrollbar.pack( side = RIGHT, fill=Y )
                mytxt = Text(root, yscrollcommand = scrollbar.set )
                mytxt.insert(END, readopenname)
                mytxt.pack( side = LEFT, fill = BOTH )
                scrollbar.config( command = mytxt.yview )
                mainloop()