ButcherWhicks McGee
ButcherWhicks McGee

Reputation: 9

Having problems with my python code, using tkinter. I keep getting a message that says object has no attribute

# Theater Ticket Program Account Creation
# contains user name and password setup and validation

import tkinter
from tkinter import *
from tkinter import messagebox

class AccountGUI:
    def __init__(acct):

        print('In the init for AccountGUI')
        acct.account_window = tkinter.Tk()
        acct.account_window.title("Account Creation")
        acct.account_window.minsize(width=250,height=250)# set the window size
        acct.account_window.resizable(False,False)
        acct.account_window.config(bg='gray5',borderwidth= 3,relief= GROOVE)

        acct.account_window.columnconfigure(0, minsize=10)
        acct.account_window.columnconfigure(1, minsize=50)
        acct.account_window.columnconfigure(2, minsize=10)
        acct.account_window.columnconfigure(3, minsize=5)
        acct.account_window.columnconfigure(4, minsize=50)


        acct.account_window.userName_label = tkinter.Label(acct.account_window, text='Username:', font=("Helvetica",10),\
                                                           bg='gray5',fg='DarkOrange2')
        acct.account_window.userName_label.grid(row=2, column=1, pady=20)

        acct.account_window.userName_entry = tkinter.Entry(acct.account_window,width = 20, \
                                                           font=("Helvetica",10))
        acct.account_window.userName_entry.grid(row=2, column=2, padx=90, pady=20, sticky=W)
        acct.account_window.userName_entry.focus_force()

        acct.account_window.passrequ_label = tkinter.Label(acct.account_window, text= \
                                                               'Create a password of at least six (6) characters,\n'\
                                                               'that contains at least one digit, one uppercase,\n'\
                                                               'and one lowercase letter.',bg='gray5',fg='DarkOrange2',\
                                                                font=("Helvetica",10))
        acct.account_window.passrequ_label.grid(row=4, column=2,padx=10)

        acct.account_window.password_label = tkinter.Label(acct.account_window, text='Password:', font=("Helvetica",10),\
                                                           bg='gray5',fg='DarkOrange2')
        acct.account_window.password_label.grid(row=6, column=1, pady=20)

        acct.account_window.password_entry = tkinter.Entry(acct.account_window,width = 20,\
                                                           font=("Helvetica",10))
        acct.account_window.password_entry.grid(row=6, column=2, padx=90, pady=20, sticky=W)
        acct.account_window.password_entry.focus_force()

        acct.account_window.create_button = tkinter.Button(acct.account_window, text='Create Account', \
                                                           font=("Helvetica",10),bg='gray5',fg='DarkOrange2',\
                                                           command=acct.verify_new_user)
        acct.account_window.create_button.grid(row=15, column=2, columnspan=5,pady=30)

        acct.account_window.cancel_button = tkinter.Button(acct.account_window, text='Cancel', \
                                                           font=("Helvetica",10),bg='gray5',fg='DarkOrange2',\
                                                           command=acct.account_window.destroy)
        acct.account_window.cancel_button.grid(row=15, column=3,pady=30)


#This function verifies that a new user is in fact a new user name
    def verify_new_user(acct):
        valid = True
        newUser = (acct.account_window.userName_entry.get())
        print('newUser is: ' + newUser + '\n')
        try:
            userDataFile = open('acct_user_names.txt', 'r')

            for userTemp in userDataFile:
                print('userTemp from file is: ' + userTemp)
                if newUser == userTemp.rstrip():
                    valid = False

            userDataFile.close()

            if (valid == False):    
                tkinter.messagebox.showinfo('Invalid User Name','That user name already exists.')
                acct.account_window.userName_entry.delete(0,END)
                acct.account_window.userName_entry.focus_force()   
                acct.account_window.lift()
            else:    
                acct.verify_new_pass(newUser)

        except IOError:
            print('No File exists.')


    def verify_new_pass(acct, user):
        valid = False
        txt = (acct.account_window.password_entry.get())      
        print('Getting password   ' + txt)

        if acct.verify_pass(txt):     
            userFile = open('acct_user_names.txt', 'a')    
            userFile.write(user + '\n')
            userFile.close()

            passwordFile = open('acct_user_passwords.txt', 'a')    
            passwordFile.write(txt + '\n')                        
            passwordFile.close()
            tkinter.messagebox.showinfo('Account Creation','Account Successfully Created.')
            acct.account_window.lift()
            acct.account_window.destroy()     
        else:
            tkinter.messagebox.showinfo('Password Validation', '"' + txt + '"' + ' is not a valid password')

    def create_account(self):
         print('Inside create_account and creating the GUI')     
         CreateAcctWin = data_create.acct.AccountGUI()

         CreateAcctWin.account_window.wait_window()

         self.create_acct_button.config(state = DISABLED)  
         self.login_button.config(state = NORMAL)


data_create_acct = AccountGUI

When I run the program I and try to create an account I get this: Create Account

Error message I receive: Error message I receive

Upvotes: 0

Views: 70

Answers (1)

ipaleka
ipaleka

Reputation: 3967

You're completely missing that verify_pass method in your class. Dunno what it's used for, I assume it's some validation for password length, consisting of both numeric and alpha characters, etc.

def verify_pass(acct, txt):
    if len(txt) < 4:
        return False
    return True

Also, do change that acct to self for consistency (create_account use it) and regarding Python's best practice.

Upvotes: 1

Related Questions