text组件的window组件创造问题
from tkinter import *root = Tk()
text = Text(root,width = 30, height = 8)
text.pack()
text.insert(INSERT,'jsfkfhjkhf')
text.insert(INSERT,'jsfkfhjkhf')
text.insert(INSERT,'\ndd')
text.insert(INSERT,'mm')
def shoy():
print('点我点我')
thebutton = Button(text,text = 'nihao',command= shoy)
text.window_create(INSERT,window = thebutton)
mainloop()
这一段代码我有一段搞不懂
有谁能解释一下text.window_create(INSERT,window = thebutton)这一段是什么意思{:9_241:} text.window_create(INSERT, window=thebutton)这一行代码的意思是在Text组件中的当前光标位置插入一个窗口组件(Button组件)。
具体来说,INSERT是一个特殊的索引,表示Text组件中当前光标的位置。window参数指定要插入的窗口组件,这里是thebutton,即一个Button组件的实例。
所以,这行代码的作用是在Text组件中的当前光标位置插入一个Button组件,从而实现在文本中嵌入一个可点击的按钮。 看这篇文章:https://fishc.com.cn/thread-59444-1-1.html
最后面有 “Indexes 用法”
页:
[1]