I call a class called Login_window with two variables "equaling" it ( wasnt sure how to word that but you'll see in the code) and when this line runs an error occurs: "TypeError: 'Login_window' object is not iterable". Although this error appears the entry window still appears how its meant and i can print of the entry if i dont have Login_window "equal" two variables.

我调用了一个名为Login_window的类,其中有两个变量“等于”它(不确定如何说出,但你会在代码中看到),当这行运行时出现错误:“TypeError:'Login_window'对象不可迭代”。虽然出现了这个错误,但是如果我没有Login_window“相等”的两个变量,那么输入窗口仍然会出现它的意思,我可以打印该条目。

Heres the code that goes wrong ( i didnt include alot of it because the rest works and is not needed ):

继承错误的代码(我没有包括很多,因为其余的工作,不需要):

class Login_window():
    def __init__(self,window):
        self.window = window
        self.window.title("Login")

        top_frame = LabelFrame(self.window)
        top_frame.grid(row=0,column=0)

        mid_frame = LabelFrame(self.window)
        mid_frame.grid(row=2,column=0)

        bottom_frame= LabelFrame(self.window)
        bottom_frame.grid(row=3,column=0)
        Label(top_frame,text = "Enter username:").grid(row=1,column=0)
        self.username_entry = Entry(top_frame)
        self.username_entry.grid(row = 1, column = 1)

        Label(mid_frame,text = "Enter password:").grid(row=3,column=0)
        self.password_entry = Entry(mid_frame)
        self.password_entry.grid(row = 3,column = 3)

        ttk.Button(bottom_frame , text = 'Enter',command = self.returN).grid(row=4,column=0)

    def returN(self):
        username=self.username_entry.get()
        password=self.password_entry.get()
        return username,password


def start():
    window=Tk()
    username,password=Login_window(window)
    return username,password
    window.mainloop()

1 个解决方案

#1


0

Your start() function is not working properly, as below:

你的start()函数无法正常工作,如下所示:

def start():
    window=Tk()
    username,password = Login_window(window)
    return username,password
    window.mainloop()

Firstly, you cannot execute the code window.mainloop() after the function returns.

首先,在函数返回后,您无法执行代码window.mainloop()。

Secondly, your Login_window class cannot be assigned to two variables like you have done. That what the "not itterable" error means. You would need a tuple with two values to do that. For example: username, password = ("my_username", "my_password")

其次,您的Login_window类不能像您一样分配给两个变量。这是“不可行”的错误意味着什么。你需要一个有两个值的元组才能做到这一点。例如:username,password =(“my_username”,“my_password”)

Yours is a custom object so if you want two variables to be set to it, do it on two lines:

你的是一个自定义对象,所以如果你想要设置两个变量,可以在两行上做:

username = Login_window(window) password = Login_window(window)

username = Login_window(window)password = Login_window(window)

Note that this does not make sense either, as you only have one window (equal to Tk()) so why do you need to reference it twice? Also, it is not clear why variables like username and password should be equal to a window object rather than just strings.

请注意,这也没有意义,因为您只有一个窗口(等于Tk())所以为什么需要引用它两次?此外,还不清楚为什么像用户名和密码这样的变量应该等于窗口对象而不仅仅是字符串。

Finally, the return(self) method looks like it should be part of your class, but the indentation means that it is not.

最后,return(self)方法看起来应该是你的类的一部分,但缩进意味着它不是。

We would need more information on what you are trying to achieve in order to help you.

我们需要更多关于您要实现的目标的信息,以便为您提供帮助。

更多相关文章

  1. 如何正确地获取在pysnmp中被捕获的变量的表行索引和命名值?
  2. python中查看变量内存地址的方法
  3. 第四章 Python 对象
  4. Shell脚本更改带变量的目录
  5. 在linux bash do循环中保持变量的值
  6. 堆栈/帧指针作为外部变量
  7. 《Linux命令行与shell脚本》笔记--第5章:使用Linux环境变量
  8. Ubuntu系统环境变量详解
  9. Debian下环境变量设置

随机推荐

  1. 学习Android开发的好教程
  2. Android通过编码实现GPS开关
  3. Android P sensor对某个APP方向做旋转
  4. android 8.0、8.1 崩溃报 "Only fullscre
  5. android下对xml的解析
  6. 关于android Error:Execution failed for
  7. android 加密 解密
  8. android 开启关闭wifi服务
  9. 【Android】获取WIFI列表简单小例子
  10. 运行时报错:Invoke-customs are only supp