Python GUI编程(Tkinter)——Entry and Text

#pack有先后次序!!
import tkinter as tk
window = tk.Tk() #新建窗口对象
window.title('my window') #窗口名
window.geometry('200x200')#窗口大小

entry = tk.Entry(window,show=None)#新建entry对象,显示为原值
#(如果show参数设置为show=something表示显示为something)
entry.pack()

text = tk.Text(window,height=2)#新建text对象,height为行数
text.pack()

def insert_point():
    variable = entry.get()
    text.insert('insert',variable)
    
def insert_end():
    variable = entry.get()
    text.insert('end',variable)
    #参数还可以设置为具体位置(x,y):text.insert(x.y,variable)

button_1 = tk.Button(window,text='insert point',
                   width=15,height=2,command=insert_point)#新建按钮,命令关联到hit_me这个函数
button_1.pack()#放置按钮

button_2 = tk.Button(window,text='insert end',
                   width=15,height=2,command=insert_end)
button_2.pack()


window.mainloop()#持续刷新window


posted @ 2020-07-22 06:20  zjx_thu  阅读(176)  评论(0编辑  收藏  举报
/* 看板娘 */