import tkinter
win = tkinter.Tk()
win.title("fanfan")
win.geometry("400x400+200+0")'''
文本控件,用于显示多行文本
'''# height显示的行数
text = tkinter.Text(win, width=30, height=4)
text.pack()str="""That we are in the midst of crisis is now well understood. Our nation is at war, against a far-reaching network of violence and hatred. Our economy is badly weakened, a consequence of greed and irresponsibility on the part of some, but also our collective failure to make hard choices and prepare the nation for a new age. Homes have been lost; jobs shed; businesses shuttered. Our health care is too costly; our schools fail too many; and each day brings further evidence that the ways we use energy strengthen our adversaries and threaten our planet."""
text.insert(tkinter.INSERT,str)
win.mainloop()
7、带滚动条的text
import tkinter
win = tkinter.Tk()
win.title("fanfan")# win.geometry("400x400+200+0")'''
文本控件,用于显示多行文本
'''#创建滚动条
scroll = tkinter.Scrollbar()
text = tkinter.Text(win, width=50, height=8)#side放到窗体的右侧# fill填充
scroll.pack(side=tkinter.RIGHT, fill=tkinter.Y)
text.pack(side=tkinter.LEFT, fill=tkinter.Y)str="""That we are in the midst of crisis is now well understood. Our nation is at war, against a far-reaching network of violence and hatred. Our economy is badly weakened, a consequence of greed and irresponsibility on the part of some, but also our collective failure to make hard choices and prepare the nation for a new age. Homes have been lost; jobs shed; businesses shuttered. Our health care is too costly; our schools fail too many; and each day brings further evidence that the ways we use energy strengthen our adversaries and threaten our planet.That we are in the midst of crisis is now well understood. Our nation is at war, against a far-reaching network of violence and hatred. Our economy is badly weakened, a consequence of greed and irresponsibility on the part of some, but also our collective failure to make hard choices and prepare the nation for a new age. Homes have been lost; jobs shed; businesses shuttered. Our health care is too costly; our schools fail too many; and each day brings further evidence that the ways we use energy strengthen our adversaries and threaten our planet."""
text.insert(tkinter.INSERT,str)#关联
scroll.config(command=text.yview)
text.config(yscrollcommand=scroll.set)
win.mainloop()