1 回答
TA贡献1810条经验 获得超5个赞
python shell 使实验变得很容易。假设错误是因为enter我刚刚将代码的第一部分粘贴到 shell 中。
>>> import tkinter as tk
>>> from tkinter import *
>>>
>>> root = tk.Tk()
>>>
>>> enter = tk.Entry(root, width = 35, borderwidth = 5).grid(row = 0, column = 0, columnspan = 3, padx =10 , pady = 10)
>>> repr(enter)
'None'
是的,它的None。这是典型的。对象方法通常不返回自己的对象。它对于方法链接很方便,但大多数对象并不是为此而设计的。只需按照示例和教程所示操作即可,并将其放在单独的行中。
import tkinter as tk
from tkinter import *
root = tk.Tk()
enter = tk.Entry(root, width = 35, borderwidth = 5)
enter.grid(row = 0, column = 0, columnspan = 3, padx =10 , pady = 10)
def ButtonClick(number):
print(number)
current = enter.get()
print(current)
# enter.delete(0,END)
# enter.insert(0, current + number)
button1 = tk.Button(root, text="1", bg="yellow",padx = 40, pady= 20, command=lambda: ButtonClick(1)).grid(row = 1, column = 0)
root.mainloop()
添加回答
举报