1. 程式人生 > >33.4 python中insert()的用法

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,就是往下面一行行的寫