没有功能"tk"的“功能"对象是什么意思? [英] What does 'function' object has no attribute 'tk' mean?
问题描述
我目前正在开发一个程序,该程序可以让您注册一个帐户,然后通过将详细信息写入txt文档并再次阅读来再次登录,直到我添加以下内容,一切正常为止:
I'm currently working on a program that lets you sign up to an account, and login again by writing the details to a txt document and reading them again, everything was working fine until I added this:
def login():
fh = open("usernamepassword.txt", "r")
lines = fh.readlines()
fh.close()
username=(lines[0])
fname=(lines[2])
lname=(lines[3])
本节尚未结束,但是每当我在不带三引号的情况下运行脚本时,都会出现此错误:
This section isn't finished yet, but whenever I run the script without this in triple quotations, I get this error:
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学习.
As you can see above, the variable 'b2' isn't related to the section above that what-so-ever. I've looked in tkinter's init file but, as I'm a beginner in python, there wasn't anything I could find there. I've searched for hours online for solutions to this problem, but I just can't find any! I really need this question answered as this goes toward my GCSE in computer science.
推荐答案
您要插入功能 login
作为按钮的父窗口小部件:
you are plugging the function login
as the parent widget for your button :
b2=Button(login, text="Don't have an account? Make one here!", command=signupswitch)
用您的根窗口小部件或任何父窗口小部件替换登录
.
Replace login
with your root widget or whatever the parent widget is.
这篇关于没有功能"tk"的“功能"对象是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!