“函数”对象没有属性“tk”是什么意思?

2024-03-17

我目前正在开发一个程序,可以让您注册一个帐户,然后通过将详细信息写入 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 课程。


你正在插入这个函数login作为按钮的父小部件:

b2=Button(login, text="Don't have an account? Make one here!", command=signupswitch)

Replace login使用您的根小部件或任何父小部件。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“函数”对象没有属性“tk”是什么意思? 的相关文章

随机推荐