Python tkinter的text控件加滚动条
"""文本控件:用于显示多行文本"""import tkinterwin = tkinter.Tk()win.title('带滚动条text控件')# win.geometry('400x400')text = tkinter.Text(win,width=50,height=8)scroll = tkinter.Scrollbar()# 放到窗口的右侧, 填充Y竖直方向scroll.pack(s
·
"""
文本控件:用于显示多行文本
"""
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()
更多推荐
已为社区贡献2条内容
所有评论(0)