33.4 python中insert()的用法

xiaoxiao2025-05-31  43

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

转载请注明原文地址: https://www.6miu.com/read-5031044.html

最新回复(0)