python-Tkinter文本组件Text(九)

 python-Tkinter文本组件Text(九)

from tkinter import *
'''
Text组件
'''
root = Tk()

#width=30,height=2 表示预留30个文字宽度,50行文字高度
text = Text(root,width=30,height=50)
text.pack()

#Text插入文本
#INSERT表示在光标位置插入内容
text.insert(INSERT,'在光标位置插入 \n')
text.insert(END,'在末尾插入')

#Text插入组件和windows对象
def show():
    print("按钮点击了一下")
button = Button(text,text="按钮名称",command=show)
text.window_create(INSERT,window=button)

#Text插入图片
photo = PhotoImage(file='xiaoxiang.gif')
def show():
    text.image_create(END,image=photo)
button = Button(text,text="按钮名称",command=show)
text.window_create(INSERT,window=button)


mainloop()

猜你喜欢

转载自blog.csdn.net/m0_38039437/article/details/80650378
今日推荐