Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将滚动条添加到文本小部件?_Python_User Interface_Tkinter - Fatal编程技术网

Python 如何将滚动条添加到文本小部件?

Python 如何将滚动条添加到文本小部件?,python,user-interface,tkinter,Python,User Interface,Tkinter,如果文本小部件位于顶级小部件内部,并通过网格几何管理器添加到布局中,则如何将滚动条添加到文本小部件 我的意思是,我在“顶级”窗口/对话框中看到了: ttk.Label(toplevel,text="Text Area").grid(row=8,sticky=E) self.TextAreaCCOrder=Text(toplevel,height=10,width=50 ).grid(row=8,column=1) PS:I'm noob:)下面是一个使用滚动条和文本小部件创建框架的示例: im

如果文本小部件位于顶级小部件内部,并通过网格几何管理器添加到布局中,则如何将滚动条添加到文本小部件

我的意思是,我在“顶级”窗口/对话框中看到了:

ttk.Label(toplevel,text="Text Area").grid(row=8,sticky=E)
self.TextAreaCCOrder=Text(toplevel,height=10,width=50 ).grid(row=8,column=1)

PS:I'm noob:)

下面是一个使用滚动条和文本小部件创建框架的示例:

import Tkinter as tk

class Example(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)

        # create the text and scrollbar widgets
        text = tk.Text(self, wrap="word")
        vsb = tk.Scrollbar(self, orient="vertical")

        # connect them to each other
        text.configure(yscrollcommand=vsb.set)
        vsb.configure(command=text.yview)

        # use grid to arrange the widgets (though pack is simpler if
        # you only have a single scrollbar)
        vsb.grid(row=0, column=1, sticky="ns")
        text.grid(row=0, column=0, sticky="nsew")

        # configure grid such that the cell containing the text
        # widget grows and shrinks with the window
        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)

if __name__ == "__main__":
    root = tk.Tk()
    frame = Example(parent=root)
    frame.pack(side="top", fill="both", expand=True)

    root.mainloop()

谢谢你,你的回答也回答了另一个我没有问的问题:)