属性错误:类型对象'StartPage'没有属性'Username_Text'

时间:2019-06-20 12:12:16

标签: python

我正在尝试从另一个类中以stringvar的形式调用,但是出现以下错误:

AttributeError: type object 'class' has no attribute 'stringVar'

请查看下面的代码,我不知道我在做什么错。

如果我将其添加到我的代码中

StartPage_object = StartPage()

USER = StartPage_object.Username_Text.get()
PASSWORD = StartPage_object.Password_Text.get()

它给了我一个新的错误:

__init__() missing 2 required positional arguments: 'parent' and 'controller'

如果我添加这个

StartPage_object = StartPage(self)

USER = StartPage_object.Username_Text.get()
PASSWORD = StartPage_object.Password_Text.get()

它给了我一个新的错误:

name 'self' is not defined

class StartPage(tk.Frame):

     def __init__(self, parent, controller):
         tk.Frame.__init__(self,parent)

#=============Set_Background==================>
     load1 = Image.open(Image_File +"\Login_Bcakground.png")
     render1 =ImageTk.PhotoImage(load1)

#========= Reset_username & Password ===========>
     Username_Text= tk.StringVar()
     Password_Text= tk.StringVar()

#==== Creating Buttons, Entry Box and Labels with there commands ========>

     Login_button = tk.Button(self, text="Login", 
                   fg="#d0cece",bg="#3f9a84",borderwidth = 0, 
                   font=Normal_Text,height =1,width = 10,
                            command=lambda: Login_Check())
     Login_button.place(x=1010,y=380)


     User_Name_Entry = tk.Entry(self,textvariable = Username_Text, fg = 
                        Entry_Box_Text_Colour,bg = 
                        Entry_Box_Back_White,borderwidth = 0, 
                        font=Normal_Text,width = 30)
     User_Name_Entry.place(x=795,y=282)

     User_Pass_Entry = tk.Entry(self,textvariable = Password_Text, fg = 
                       Entry_Box_Text_Colour,bg = 
                       Entry_Box_Back_White,borderwidth = 0, 
                       font=Normal_Text,width = 30)
     User_Pass_Entry.place(x=795,y=329)

#===============Login==========================Login====================>

下一个代码不是要使n成为球状变量的类

USER = StartPage.Username_Text.get()
PASSWORD = StartPage.Password_Text.get()

0 个答案:

没有答案