33.4 python中insert()的用法

#tk-button
#python3
from tkinter import *

er = Tk()
er.title("tk-button")
er.geometry('500x400')

def printhello():
    t.insert('2.1', "hello\n")
def printpress():
    t.insert('1.0', "press\n")
##    print(t)
##    t.insert('2.0', "hello\n")

t = Text()
print(t)
t.pack()
Button(er, text = 'hello', command = printhello).pack(side = LEFT)
Button(er, text = 'press', command = printpress).pack(side = LEFT)
er.mainloop()

python的insert函数中有两个必填参数,第一个是填充的位置,第二个是填充的内容。必须有小数点,不然报错。一般用1.0,就是往下面一行行的写

你可能感兴趣的:(python)