|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- from tkinter import *
- root = Tk()
- Label(root,text="账号:").grid(row=0,column=0)
- Label(root,text="密码:").grid(row=1,column=0)
- v1 = StringVar()
- v2 = StringVar()
- e1 = Entry(root,textvariable=v1)
- e2 = Entry(root,textvariable=v2,show="*")
- e1.grid(row=0,column=1,padx=10,pady=5)
- e2.grid(row=1,column=1,padx=10,pady=5)
- def show():
- print (u"账号:%s")% e1.get()
- print (u"密码:%s")% e2.get()
- Button(root,text="芝麻开门",width=10,command=show)\
- .grid(row=3,column=0,sticky=W,padx=10,pady=5)
- Button(root,text="退出",width=10,command=root.quit)\
- .grid(row=3,column=1,sticky=E,padx=10,pady=5)
- mainloop()
复制代码
报错信息如下:
Exception in Tkinter callback
Traceback (most recent call last):
File "E:\Python34\lib\tkinter\__init__.py", line 1487, in __call__
return self.func(*args)
File "E:/Python34/7.py", line 17, in show
print (u"账号:%s")% e1.get()
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'
本帖最后由 isdkz 于 2022-2-17 14:36 编辑
改一下16到18行,那是python2的写法
- def show():
- print("账号:%s" % e1.get())
- print("密码:%s" % e2.get())
复制代码
|
|