具有属性错误的GUI

时间:2014-04-22 18:08:26

标签: python user-interface python-3.3 attributeerror

这可能很多,如果有人可以帮助我,那就太好了!我插入这个。

from graphics import *
w = GraphWin ("Graphics Window", 400, 400)
update()
x = input("Press Enter")

import random

class RPC:
    def __init__(self):
        self.comChoice = ''
        self.choices = ['Rock', 'Paper', 'Scissors']

    def chooseCom(self):
        self.comChoice = self.choices[random.randint(0,2)]
        return self.comChoice

    def player(self, choice, Com):
         if choice == 'rock' and Com == 'Scissors':
             return ('You won!')
         elif choice == 'paper' and Com == 'Rock':
             return ('You won!')
         elif choice == 'scissors' and Com == 'Paper':
             return('You won!')
         elif choice == 'scissors' and Com == 'Rock':
             return ('You lost!')
         elif choice == 'rock' and Com== 'Paper':
             return('You lost!')
         elif choice == 'paper' and Com == 'Scissors':
             return ('You lost!')
         else:
             return ('Tie!')

    from tkinter import *


    def ComputerChoice():
        game = RPCclass.RPC()
        c = game.chooseCom()
        return c

    def winner(choice, Com):
        game = RPCclass.RPC()
        w = game.player(choice, Com)
        return w

    def numWin(self, choice, Com):
        game = RPCclass.RPC()
        a = game.player(choice, Com)
        if a == 'You win!':
                self.numPlayerWin += 1
        elif a == 'You lost!':
                self.numComwin += 0
                self.numComWin += 0

        self.message4.config(text = 'Player won ' + \
                                 str(self.numPlayerWin) + ' times.')
        self.message5.config(text = 'Computer won ' + \
                                 str(self.numComWin) + ' times.')

    class GUI():
    def __init__(self):
        root = Tk()
        root.title('Welcome to Rock Paper Scissors')

        self.numComWin = 0
        self.numPlayerWin = 0

        self.label = Label(root, text='"Choose Rock, Paper, or Scissors."',
                               fg='Black',
                               bd=10)
        self.label.grid(row=5, columnspan = 3)

        self.button1 =  Button(root, text='Rock',
                                   bg='Blue',
                                   fg='white',
                                   padx=10, pady=5,
                                   command=self.buttonAction1)
        self.button1.grid(row=7, column=0, rowspan=2)

        self.button2 =  Button(root, text='Paper',
                                   bg='Blue',
                                   fg='white',
                                   padx=10, pady=5,
                                   command=self.buttonAction2)
        self.button2.grid(row=7, column =1, rowspan =2)

        self.button3 =  Button(root, text='Scissors',
                                   bg='blue',
                                   fg='white',
                                   padx=10, pady=5,
                                   command=self.buttonAction3)
        self.button3.grid(row=7, column =2, rowspan=2)

        self.button4 =  Button(root, text='Reset',
                                   bg='black',
                                   fg='white',
                                   padx=10, pady=5,
                                   command=self.buttonAction4)
        self.button4.grid(row=12, column =1, rowspan=2)

        self.message1 = Label(root, text='',fg='Black')
        self.message1.grid(row=9, columnspan=3)

        self.message2 = Label(root, text='',fg='Black')
        self.message2.grid(row=10, columnspan=3)

        self.message3 = Label(root, text='',fg='Red', font=('Times',16,'bold'))
        self.message3.grid(row=11, columnspan=3)

        self.message4 = Label(root, text='',fg='black')
        self.message4.grid(row=12, column=0, rowspan=2)

        self.message5 = Label(root, text='',fg='black')
        self.message5.grid(row=12, column=2, rowspan=2)

        root.mainloop()

    def buttonAction1(self):
        choice = 'rock'
        self.message1.config(text= 'You choose Rock.')
        Com = ComputerChoice()
        self.message2.config(text= 'Computer has chosen %s.' % Com)
        self.message3.config(text = winner(choice, Com))
        numWin(self,choice, Com)

    def buttonAction2(self):
        choice = 'paper'
        self.message1.config(text= 'You choose Paper.')
        Com = ComputerChoice()
        self.message2.config(text= 'Computer has chosen %s.' % Com)
        self.message3.config(text = winner(choice, Com))
        numWin(self,choice, Com)

    def buttonAction3(self):
        choice = 'scissors'
        self.message1.config(text= 'You choose Scissors.')
        Com = ComputerChoice()
        self.message2.config(text= 'Computer has chosen %s.' % Com)
        self.message3.config(text = winner(choice, Com))
        numWin(self,choice, Com)

    def buttonAction4(self):
        self.message1.config(text= '')
        self.message2.config(text= '')
        self.message3.config(text= '')
        self.numComWin = 0
        self.numPlayerWin = 0
        numWin(self,0, 0)
        self.message4.config(text = '')
        self.message5.config(text = '')

    GUI()

我的错误是

Traceback (most recent call last):
  File "/Users/eddx540/Desktop/Proj3/RPS example files/Proj3 GUI.py", line 152, in <module>
    GUI()
  File "/Users/eddx540/Desktop/Proj3/RPS example files/Proj3 GUI.py", line 77, in __init__
    command=self.buttonAction1)
AttributeError: 'GUI' object has no attribute 'buttonAction1'

0 个答案:

没有答案