Python 图形界面之 tkinter

示例

 

import tkinter as tk


win = tk.Tk()
win.title('手撸代码')
win.geometry('500x200')

lable1 = tk.Label(win, bg='green', text='Left')
lable1.pack(side=tk.LEFT)

lable2 = tk.Label(win, bg='blue', text='Right')
lable2.pack(side=tk.RIGHT)

text = tk.Text(win, bg='greenyellow',  height=4, width=40 )
# text.pack()
text.place(x=60, y=80, anchor='nw')  # 精确定位place,anchor='nw',表示锚定点为西北角

entry = tk.Entry(win, bg='yellow', show='*')
entry.pack()

def func():
    # print('btn is clicked!')
    str = entry.get()
    # str = text.get('0.0','end')  # 文本框获取内容,第一行第一列  结尾
    text.insert('insert', 'Text :' + str)  # 在鼠标焦点处插入输入内容
    

btn = tk.Button(win,text='在上面的文本框种输入文字,然后点我!', width=40, height=2, command=func)
btn.pack(anchor=tk.E)   # N S W E 对应 北 南 西(左) 东(右)

win.mainloop()

 

posted @ 2020-05-24 15:18  jenas  阅读(186)  评论(0)    收藏  举报