Python2.7 .pack()的坑

import Tkinter as tk
window = tk.Tk()
window.title('My Window')
window.geometry('500x300')  # 这里的乘是小x
e = tk.Entry(window, show = None)#显示成明文形式
e.pack()
def insert_point(): # 在鼠标焦点处插入输入内容
    var = e.get()
    t.insert('insert', var)
def insert_end():   # 在文本框内容最后接着插入输入内容
    var = e.get()
    t.insert('end', var)
b1 = tk.Button(window, text='insert point', width=10,
               height=2, command=insert_point)
b1.pack()
b2 = tk.Button(window, text='insert end', width=10,
               height=2, command=insert_end)
b2.pack()
t = tk.Text(window, height=3)
t.pack()

'''

如果t = tk.Text(windows,height=5).pack() 连在一起程序会报错 File "D:\****\***.py", line 24, in insert_point
    t.insert('insert', var)
AttributeError: 'NoneType' object has no attribute 'insert'

'''
window.mainloop()

你可能感兴趣的:(Python2.7 .pack()的坑)