保温材料,特价话费,火星救援 字幕
text: 文本控件;用于显示多行文本
一、基本使用
1、插入文字、组件、图片
插入内容如下:
代码1如下:
# coding:utf8 from tkinter import * """ 1.text插入组件;2.text插入图片;""" class app: def __init__(self, master): photo = photoimage(file='456.png') # text组件 frame = frame(master).pack(padx=5, pady=5) text = text(frame, width=100, height=30) text.pack() # 插入数据 文档、图片、组件 text.insert(insert, "插入开头\n") text.insert(end, "插入结尾") # 插入图片 def show(): text.image_create(end, image=photo) b = button(text, text='插入图片', command=show) text.window_create(insert, window=b) root = tk() win = app(root) root.mainloop()
2、读取文本内容
代码2如下:
# coding:utf8 from tkinter import * """ 1.text插入组件;2.text插入图片;""" class app: def __init__(self, master): photo = photoimage(file='456.png') # text组件 frame = frame(master).pack(padx=5, pady=5) label(frame, text="请在文本框输入您的内容").pack() text = text(frame, width=100, height=30) text.pack() # 使用get获取text的内容 def printt1(): print("您输入的内容是:", text.get("0.0", end)) button(frame, text="点击打印您输入的内容", command=printt1).pack() root = tk() win = app(root) root.mainloop()
效果如下:
读书和健身总有一个在路上
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
python求numpy中array按列非零元素的平均值案例
网友评论