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()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章