import tkinter
# place()和pack()的區別
# place可以自定義設置控件顯示坐標
# pack自動設置控件的位置在畫板中間,並按照pack順序進行顯示布局
# insert函數,根據Text中指定位置設置值,例如Text.insert('0.0',
# tk窗口布局
# 在Text輸入框尾部插入
def insert():
u = m_Edit.get()
m_Text.insert('end', u + '\n')
# 在Text輸入框頭部插入
def fount_insert():
u = m_Edit.get()
m_Text.insert('0.0', u + '\n')
def Text_delete():
m_Text.delete('0.0', 'end')
# 獲取Text中所有數據, 0.0表示獲取首位置,end表示結尾,
def Text_Get():
u = m_Text.get('0.0', 'end')
m_Edit.insert(0, u)
return u
# 初始化tkiner畫板
top = tkinter.Tk()
# 初始化標題
top.title('helloworld')
# 畫板大小 畫板大小1920x1080 顯示位置xy軸坐標+30 +30
top.geometry("1920x1080+30+30")
# 創建Text面板
m_Text = tkinter.Text(top)
# 設置Text坐標, 坐標以及窗口的大小
m_Text.place(x=500, y=150, width=800, height=800)
m_Edit = tkinter.Entry(top)
m_Edit.place(x=50, y=200, width=300, height=20)
# 設置按鈕的大小
Text_pushback_button = tkinter.Button(top, text='PushBack_Text尾部添加', command=insert)
Text_pushback_button.place(x=550, y=100, width=300, height=50)
# 綁定按鈕觸發的函數,參數為主程序,按鈕上顯示的文字,觸發的函數,
text_deleteAll_button = tkinter.Button(top, text='Text刪除全部數據', command=Text_delete)
text_deleteAll_button.pack()
text_button_fount = tkinter.Button(top, text='fount_insert,Text頭部插入數據', command=fount_insert)
text_button_fount.pack()
text_button_GetData = tkinter.Button(top, text='GetData,獲取Text數據', command=Text_Get)
text_button_GetData.pack()
# 結束窗口布局操作,無此函數,畫板將不顯示
top.mainloop()