我目前正在开发一个程序,可以让您注册一个帐户,然后通过将详细信息写入 txt 文档并再次读取它们来再次登录,一切都工作正常,直到我添加以下内容:
def login():
fh = open("usernamepassword.txt", "r")
lines = fh.readlines()
fh.close()
username=(lines[0])
fname=(lines[2])
lname=(lines[3])
本节尚未完成,但每当我运行没有三重引号的脚本时,都会收到此错误:
Traceback (most recent call last):
File "C:\Users\Robbie\Documents\Python\Signup - Login.py", line 274, in <module>
b2=Button(login, text="Don't have an account? Make one here!", command=signupswitch)
File "C:\Users\Robbie\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 2209, in __init__
Widget.__init__(self, master, 'button', cnf, kw)
File "C:\Users\Robbie\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 2132, in __init__
BaseWidget._setup(self, master, cnf)
File "C:\Users\Robbie\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 2110, in _setup
self.tk = master.tk
AttributeError: 'function' object has no attribute 'tk'
正如您在上面看到的,变量“b2”与上面的部分无关。我看过 tkinter 的init文件,但是,由于我是 python 的初学者,所以我在那里找不到任何东西。我在网上搜索了几个小时来寻找这个问题的解决方案,但我找不到任何解决方案!我真的需要回答这个问题,因为这将影响我的计算机科学 GCSE 课程。