tkinter_Entry和text

#encoding=utf-8
import tkinter as tk
#创建窗口,设置标题,大小
window = tk.Tk()
window.title("我的窗口")
window.geometry("400x200")

#创建一个Entry输入框,输入框输入字符以星号展示,show=None,展示原文,show="1"
#展示1
entry = tk.Entry(window,show="*")
entry.pack()

#定义函数:获取Entry输入框的内容并且插入到text文本框中
#插入到text文本框的当前光标位置
def insert_point():
    entry_content = entry.get()
    text.insert("insert",entry_content)#text.insert("1.1",entry_content)插入到text文本框1行1列位置

#定义函数:获取Entry输入框的内容并且插入到text文本框中
#插入到text文本框的末尾
def insert_end():
    entry_content = entry.get()
    text.insert("end",entry_content)

#创建Button,执行insert_point函数
button_1 = tk.Button(window,text="insert point",width=15,height=2,font=10,command = insert_point)
button_1.pack()
#创建Button,执行insert_end数
button_2 = tk.Button(window,text="insert end",width=15,height=2,font=12,command=insert_end)
button_2.pack()

#创建Text输入框
text = tk.Text(window,width=20,height=2)
text.pack()

#循环检测窗口
window.mainloop()

猜你喜欢

转载自blog.51cto.com/13496943/2311070