码迷,mamicode.com
首页 > 其他好文 > 详细

tkinter text widget 第一节

时间:2017-09-27 10:22:20      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:conf   let   内容   rac   roo   a long   which   and   ext   

>>> from tkinter import *
>>> root=Tk()
>>> text=Text(root,width=40,height=10)    #创建一个text 文本框。长度是40 pixel 高度是10pixel
>>> text.pack()                                           #排版
>>> text.config(wrap = ‘word‘)                    #以word 来wrap? 最短单位是单词
>>> text.get(‘1.0‘,‘end‘)                               #1表示第一行(从1 开始),。0 表示第一个字节(0开始),end表示整个文本框的结束
‘This is a long message in the text box which is more than 40 characters.\n\n\n\n\n\n\nIf the message hits the bottom of the thext box it will run off the screen.\n‘
>>> text.get(‘1.0‘,‘1.end‘)                           #从第一行第一个字节开始到第一行最后
‘This is a long message in the text box which is more than 40 characters.‘
>>> text.insert(‘1.0+2 lines‘,‘Inserted message‘)             #  第一行过后两行。第三行 插入内容“Inserted message”
>>> text.get(‘2.0‘)                                        #get第二行的第一个字节。 第二行是空的换行所以为\n

‘\n‘
>>> text.get(‘3.0‘)                  
‘I‘
>>> text.get(‘3.0‘,‘end‘)
‘Inserted message\n\n\n\n\nIf the message hits the bottom of the thext box it will run off the screen.\n‘
>>> text.get(‘3.0‘,‘3.end‘)
‘Inserted message‘
>>> text.get(‘4.0‘,‘4.end‘)                           #从第四行第一个字节开始。到底四行结尾
‘‘
>>> text.insert(‘1.0+2lines lineend‘,‘and\nmore and \nmore...‘)  
>>> text.delete(‘1.0‘)                                  #删除第一行第一个字节
>>> text.delete(‘1.0‘,‘1.0 lineend‘)                 #删除第一行第一个字节开始到第一行最后
>>> text.delete(‘1.0‘,‘3.0 lineend +1 chars‘)   #删除第一行开始 第三行结束。 并且加上最后一个字节
>>> text.replace(‘1.0‘,‘3.0 lineend‘,‘This is the first line.‘)
>>> text.config(state=‘disabled‘)                 #配置text的状态。disable就无法输入了
>>> text.delete(‘1.0‘,‘end‘)
>>> text.config(state=‘normal‘)
>>>

tkinter text widget 第一节

标签:conf   let   内容   rac   roo   a long   which   and   ext   

原文地址:http://www.cnblogs.com/uxiuxi/p/7599675.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!