2013-12-07 3 views
0

Так что я пытаюсь использовать графику, чтобы сделать три отдельные кости и пока я, наконец, получил их, чтобы показать, что я теперь получаю эту ошибкуПолучение ошибки «Нет атрибута ничья»

>>> Game() 
Traceback (most recent call last): 
    File "<pyshell#0>", line 1, in <module> 
    Game() 
    File "C:\Users\Brandon\Desktop\FinalProject3.py", line 19, in Game 
    Green.draw(Gamewindow) 
AttributeError: 'DieViewGreen' object has no attribute 'draw' 

Который буквально не имеет смысла для меня, потому что графика должна была импортировать его.

Что-то не хватает в моем коде?

from graphics import * 

class DieViewGreen: 
    """ DieView is a widget that displays a graphical representation 
    of a standard six-sided die.""" 

    def __init__(self, win, center, value): 
     """Create a view of a die, e.g.: 
      d1 = GDie(myWin, Point(40,50), 20) 
     creates a die centered at (40,50) having sides 
     of length 20.""" 

     # first define some standard values 
     self.win = win 
     #self.background = Color color of die face 
     #self.foreground = Color2 # color of the pips 

     # create a square for the face 
     if value==0: 
      x, y = center.getX(), center.getY() 
      p1 = Point(x-25, y-25) 
      p2 = Point(x+25, y+25) 
      rect = Rectangle(p1,p2) 
      rect.draw(win) 
      rect.setFill('green')   

     """ Set this die to display value.""" 
     if value == 1: 
      x, y = center.getX(), center.getY() 
      p1 = Point(x-25, y-25) 
      p2 = Point(x+25, y+25) 
      rect = Rectangle(p1,p2) 
      rect.draw(win) 
      rect.setFill('green') 
      self.Brain=Text(Point(40,75),'B') 
      self.Brain.draw(self.win) 


     elif value == 2: 
      x, y = center.getX(), center.getY() 
      p1 = Point(x-25, y-25) 
      p2 = Point(x+25, y+25) 
      rect = Rectangle(p1,p2) 
      rect.draw(win) 
      rect.setFill('green') 
      self.Brain=Text(Point(40,75),'B') 
      self.Brain.draw(self.win) 

     elif value == 3: 
      x, y = center.getX(), center.getY() 
      p1 = Point(x-25, y-25) 
      p2 = Point(x+25, y+25) 
      rect = Rectangle(p1,p2) 
      rect.draw(win) 
      rect.setFill('green') 
      self.Brain=Text(Point(40,75),'B') 
      self.Brain.draw(self.win) 


     elif value == 4: 
      x, y = center.getX(), center.getY() 
      p1 = Point(x-25, y-25) 
      p2 = Point(x+25, y+25) 
      rect = Rectangle(p1,p2) 
      rect.draw(win) 
      rect.setFill('green') 
      self.Foot=Text(Point(40,75),'F') 
      self.Foot.draw(self.win) 


     elif value == 5: 
      x, y = center.getX(), center.getY() 
      p1 = Point(x-25, y-25) 
      p2 = Point(x+25, y+25) 
      rect = Rectangle(p1,p2) 
      rect.draw(win) 
      rect.setFill('green') 
      self.Foot=Text(Point(40,75),'F') 
      self.Foot.draw(self.win) 


     else: 
      x, y = center.getX(), center.getY() 
      p1 = Point(x-25, y-25) 
      p2 = Point(x+25, y+25) 
      rect = Rectangle(p1,p2) 
      rect.draw(win) 
      rect.setFill('green') 
      self.Shotgun=Text(Point(40,75),'S') 
      self.Shotgun.draw(self.win) 

Функция, что я бегу мой класс в это, он называет класс dieview в (есть три, как показано выше) и использует его, чтобы нарисовать окно

from graphics import * 
    from DieViewYellow import * 
    from DieViewGreen import * 
    from DieViewRed import * 
    from Button import * 
    import random 


    def Game(): 
     """Runs the game""" 
     Gamewindow = GraphWin('Game', 200, 200) 
     Green = DieViewGreen(Gamewindow, Point(40,75),20) 
     Yellow = DieViewYellow(Gamewindow, Point(95,75),20) 
     Red = DieViewRed(Gamewindow, Point(150,75),20) 
     Green.draw(Gamewindow) 
     Roll = Button(Gamewindow, Point(100,130), 160, 20, "Roll Dice") 
     Continue = Button(Gamewindow, Point(55,170), 70, 20, "Continue") 
     while True: 
      pt=Gamewindow.getMouse() 
      if roll.clicked(pt): 
       DieViewGreen(Gamewindow, Point(40,75),3) 
      else: 
       continue 
      #else: 
      #  Exitbutton = "Exit" 
      # Stopexit = Button(Gamewindow, Point(145,170), 70, 20, Exitbutton) 
      # Buttons = [Roll, Continue, Stopexit] 
      # for i in range(len(Buttons)): 
      #  Buttons[i].activate() 
      # n = Gamewindow.getMouse() 

ответ

2

Что эта ошибка просто означает, что у вас нет функции draw внутри вашего класса DieViewGreen. Ваша программа ожидает, что она будет такой.

+0

Я понимаю, что, но не должна функция была импортирована из графика ? – user3015380

+0

Это не то, что говорит ошибка, он ожидает, что будет функция рисования. Если вы не дадите нам больше информации, невозможно определить, что вам нужно сделать. –

+0

@ user3015380, если функция должна быть из графики, почему вы пытаетесь называть ее «зеленым»? – ApproachingDarknessFish

0

Вопрос был в моей фактической кода игры, а не мой фильеры зрения, так как я использовал Green.draw, когда мне не нужно, чтобы

Смежные вопросы