|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from tkinter import *
root=Tk()
def printinfo():
print(f"Account:{en1.get()}+\nPassword:{en2.get()}")
lab1=Label(root,text='account').grid(row=0,column=0)
lab2=Label(root,text='password').grid(row=1,column=0)
en1=Entry(root).grid(row=0,column=1)
en2=Entry(root).grid(row=1,column=1)
btn=Button(root,text='login',command=printinfo).grid(row=2,column=0)
root.mainloop()
运行后第四行报错AttributeError: 'NoneType' object has no attribute 'get'
这个题我是从台湾洪锦奎的GUITkinter书里简化改成的,printinfo()这个函数中的格式我没有用书上的方式格式化,而是用新的F“”格式化生成。就算改成和原书一样的老式%s写法也是这个错误提示。这是怎么回事。
就是想获得en1的字符串并打印出来。弄了一下午了。
- from tkinter import *
- root = Tk()
- lab1 = Label(root, text='account').grid(row=0, column=0)
- lab2 = Label(root, text='password').grid(row=1, column=0)
- en1 = Entry(root)
- en1.grid(row=0, column=1)
- en2 = Entry(root)
- en2.grid(row=1, column=1)
- def printinfo():
- print(f"Account:{en1.get()}\nPassword:{en2.get()}")
- btn = Button(root, text='login', command=printinfo).grid(row=2, column=0)
- root.mainloop()
复制代码
|
|