Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Attribute error
#1
This is what i did
from tkinter import *
import random
import time
root = Tk()

class e():
    def startofgame():
        e.Name=str(name_entry1.get())
        e.carname=str(name_entry2.get())
        b3.grid_remove()
        b1.grid()
        b2.grid()
        tex.grid()
        name_text1.grid_remove()
        name_text2.grid_remove()
        name_text3.grid_remove()
        name_entry1.grid_remove()
        name_entry2.grid_remove()
        root.geometry( '840x275' )
        
    def card():
        e.Name="Example Example"
        e.carname="example"
        e.carseats=2
        e.fuel=80
        e.speed=40
    def customercard():
        e.cName="Example Example"
        e.people=2
        e.m=0


    def order():
        b1.grid_remove()
        b2.grid_remove()
        b4.grid()
        b5.grid()
        e.people=random.randint(0,4)
        e.m=random.randint(0,10)
        if e.people>e.carseats:
            n=n+2
        elif e.people<e.carseats:
            n=n-2
        e.cName=random.randint(0,5)
        if Name==1:
            e.cName="Vanessa Roberts"
        if name==2:
            e.cName="Frank John"
        if name==3:
            e.cName="Mark Holler"
        if name==4:
            e.cName="Arnold Waller"
        if name==5:
            e.cName="Vanessa Roberts"
        if name==6:
            e.cName="Vanessa Roberts"
        if name==7:
            e.cName="Vanessa Roberts"
        if name==8:
            e.cName="Vanessa Roberts"
        if name==9:
            e.cName="Vanessa Roberts"
        if name==10:
            e.cName="Logan paul"
        tex.insert(END,"Amount of People: "+str(e.people)+"\n Minutes: "+str(e.m)+"\n Name: "+str(e.cName)+"/n")

    def takeorder():
        b4.grid_remove()
        b5.grid_remove()
        tex.insert(END,"Driving to destination")
        time.sleep(e.m)
        b1.grid
        b2.grid
        tex.insert(END,"Mision complete")
     

    
b1 = Button(root,text="order", command=e.order ,width=10,height=2)
b2 = Button(root,text="Shop",width=10,height=2)
b3 = Button(root,text="Start", command=e.startofgame ,width=10,height=2)
b4 = Button(root,text="Take order", command=e.order ,width=10,height=2)
b5 = Button(root,text="Change order", command=e.order ,width=10,height=2)
name_text1 = Label(text="Name")
name_text2 = Label(text="Car name")
name_text3 = Label(text="Enter your name \n and your car's name \n (can be made up)")
name_entry1 = Entry()
name_entry2 = Entry()
tex=Text(root,font="14",wrap=WORD,width=50,height=15)


b1.grid(row=0,column=2)
b2.grid(row=5,column=2)
b3.grid(row=4,column=3)
b4.grid(row=2,column=2)
b5.grid(row=4,column=1)
name_text1.grid(row=1, column=2)
name_text2.grid(row=2, column=2)
name_text3.grid(row=0, column=3)
name_entry1.grid(row=1,column=3)
name_entry2.grid(row=2,column=3)
tex.grid(row=0,column=1,rowspan=6)
b1.grid_remove()
b2.grid_remove()
tex.grid_remove()
root.geometry( '240x135' )
b4.grid_remove()
b5.grid_remove()
And this is what I get
Error:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Python34\lib\idlelib\run.py", line 121, in main seq, request = rpc.request_queue.get(block=True, timeout=0.05) File "C:\Python34\lib\queue.py", line 175, in get raise Empty queue.Empty During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__ return self.func(*args) File "C:\Users\Krintal\Desktop\Uber tycoon.py", line 40, in order if e.people>e.carseats: AttributeError: type object 'e' has no attribute 'carseats'
Can anyone help?
Reply
#2
Where are you calling card()?
You have to call it to instantiate the carseats attribute.

Why are you using e. and not self. inside your class?

I also suggest that you use the __init__(self) to instantiate all the attributes
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error: audioio has no attribute 'AudioOut' netwrok 3 592 Oct-22-2023, 05:53 PM
Last Post: netwrok
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,211 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Getting 'NoneType' object has no attribute 'find' error when WebScraping with BS Franky77 2 5,166 Aug-17-2021, 05:24 PM
Last Post: Franky77
  Attribute Error received not understood (Please Help) crocolicious 5 2,612 Jun-19-2021, 08:45 PM
Last Post: crocolicious
  error in scapy attribute 'haslayer' evilcode1 5 6,436 Mar-02-2021, 11:19 AM
Last Post: evilcode1
  attribute error instead of correct output MaartenRo 2 2,147 Aug-28-2020, 10:22 AM
Last Post: Larz60+
  attribute error stumped on how to fix it. hank4eva 7 4,596 Aug-11-2020, 04:47 AM
Last Post: hank4eva
  Attribute Error - trying to create a pixel array out of PNG files The_Sarco 1 1,969 Apr-29-2020, 07:10 PM
Last Post: deanhystad
  Attribute Error for Rename / Replace warden89 6 7,699 Jan-07-2020, 06:08 PM
Last Post: warden89
  Reading DBF files from Amazon s3 throwing error - 'int' object has no attribute 'isa abeesm 1 2,857 Sep-22-2019, 05:49 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020