下面是創建一個具有滾動條和文本構件框架的例子:
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()
謝謝你,你的回答也回答了我得到的另一個問題,但沒有問:) – user1983793