"""
文本控件:用于显示多行文本
"""
import tkinter
win = tkinter.Tk()
win.title('带滚动条text控件')
# win.geometry('400x400')
text = tkinter.Text(win,width=50,height=8)
scroll = tkinter.Scrollbar()
# 放到窗口的右侧, 填充Y竖直方向
scroll.pack(side=tkinter.RIGHT,fill=tkinter.Y)
# 两个控件关联
scroll.config(command=text.yview)
text.config(yscrollcommand=scroll.set)
text.pack()
str1 = 'ahh ta yu duan jian jie shi ke xi,\n' \
'mei yi ge meng xiang dou zhi de yong yi\n' \
'shi de ni shuo de dui ji le\n' \
'wo jin ran wu fa fan bo \n' \
'zaijian ba qin aid \n' \
'na zhi shi ge meihao de guo qu\n' \
'ni shi wode xiao pg \n' \
'zm ai ni dou bu xian duo\n' \
' hong h d xiao lian wen n wode xin wo\n'
text.insert(tkinter.INSERT,str1)
win.mainloop()
Python tkinter的text控件加滚动条
最新推荐文章于 2024-11-06 13:03:29 发布
关键词由CSDN通过智能技术生成