一、 Text输入框的属性

属性 参考:

Python学习笔记—— tkinter_03Button、Label_小橙子的博客-CSDN博客

Python学习笔记—— tkinter_04 Entry(单行输入框)_小橙子的博客-CSDN博客


python 弹出输入框 python窗口输入框_Text

 

二、Text输入框的方法

1.理解行和列

多行文本,确定一个位置需要使用坐标。

列数从0开始数

行数从1开始数

python 弹出输入框 python窗口输入框_python 弹出输入框_02

 2.删除,插入、获取

文本框里的内容:随意输入充当测试数据

删除,插入、获取 都需要使用坐标或光标处,结尾等确定位置。

from tkinter import *

#=========1.主窗口============
root = Tk()#创建主窗口
#=========2.创建、安放组件===========
t = Text(root,width=50,height=10,font=('宋体',20))
t.grid(row=0,column=0,columnspan=3)

b1 = Button(root,text='插入')
b1.grid(row=1,column=0)
b2 = Button(root,text='清空')
b2.grid(row=1,column=1)
b3 = Button(root,text='获取数据')
b3.grid(row=1,column=2)
#=========3.按钮事件============
def a1(e):
    #t.insert(1.0,'hello word')  #在开头插入
    t.insert(INSERT,'aaa')   #在光标处插入
    #t.insert(END,'bbb') #在结尾插入
def a2(e):
    #t.delete(1.0,END)#清空所有
    t.delete(1.0,2.2)#从第1行的第0列,到第2行的第2列
def a3(e):   
    #print(t.get(1.0,END))  #获取所有
    print(t.get(INSERT,END))#获取光标处到结尾

b1.bind('<Button-1>',a1)
b2.bind('<Button-1>',a2)
b3.bind('<Button-1>',a3)

root.mainloop()#阻止窗口关闭

python 弹出输入框 python窗口输入框_python_03