Python Forum

Full Version: Kivy problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
from kivy.uix.layout import Layout
from kivy.uix.image import Image
from kivy.uix.behaviors import ButtonBehavior
from random import shuffle
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
import time


class Board(GridLayout):
    def __init__(self):
        GridLayout.__init__(self)
        backCard1 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\backCard.png"
        card1 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Harden.jpg"
        card2 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Harden.jpg"
        card3 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Giannis.jpg"
        card4 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Giannis.jpg"
        card5 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Iverson.jpg"
        card6 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Iverson.jpg"
        card7 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Jordan.jpg"
        card8 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Jordan.jpg"
        card9 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Kobe.jpg"
        card10 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Kobe.jpg"
        card11 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\LebronJames1.jpg"
        card12 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\LebronJames1.jpg"
        card13 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\shaq.jpg"
        card14 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\shaq.jpg"
        card15 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\StephCurry.png"
        card16 = r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\StephCurry.png"
        cardList = []
        cardList.append(card1)
        cardList.append(card2)
        cardList.append(card3)
        cardList.append(card4)
        cardList.append(card5)
        cardList.append(card6)
        cardList.append(card7)
        cardList.append(card8)
        cardList.append(card9)
        cardList.append(card10)
        cardList.append(card11)
        cardList.append(card12)
        cardList.append(card13)
        cardList.append(card14)
        cardList.append(card15)
        cardList.append(card16)
        shuffle(cardList)
        # creating a Board
        self.listBoard = []
        for i in range(8):  # number of rows
            self.listLine = []  # making array listline
            for j in range(2):  # number of cols
                cell = Image_Button(self, i, j, backCard1, cardList[0], False)  # putting button
                cardList.remove(cardList[0])
                cell.x = i * 200
                cell.y = j * 200
                self.add_widget(cell)  # adding to the app window
                self.listLine.append(cell)  # adding to listline
            self.listBoard.append(self.listLine)  # adding to listboard
        redButton = Compare_Button(r"C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Button.png")
        redButton.y = 400
        redButton.x = 400
        self.add_widget(redButton)
        self.count = 0
        self.firstAdd = "a"
        self.secondAdd = "b"

    def flipOver(self):
        time.sleep(2)
        for i in self.listBoard:
            for j in i:
                if j.flip:
                    j.source = j.back
                    j.flip = False

    def deleteCards(self):
        time.sleep(2)
        for i in self.listBoard:
            for j in i:
                if j.flip:
                    self.remove_widget(j)
                    j.flip = False


class Compare_Button(ButtonBehavior, Image):
    def __init__(self, frontSource):
        ButtonBehavior.__init__(self)
        Image.__init__(self)
        self.source = frontSource

        self.front = str(frontSource)

    def on_press(self):
        print("big small")
        if str(self.board.SecondAdd) != str(self.board.firstAdd):
            print("small small")
            self.board.flipOver()
        else:
            print("small big")
            self.board.deleteCards()


class Image_Button(ButtonBehavior, Image):
    '''
    num - the number on the card
    mycolor - the color of the card
    myBord - link to the class board
    mySource - string the path to the picture
    belong- "player" or "kupa" or "open card"
    '''

    def __init__(self, i, j, myBoard, backSource, frontSource, flip):
        ButtonBehavior.__init__(self)
        Image.__init__(self)
        self.source = backSource
        self.i = i
        self.j = j
        self.board = myBoard
        self.flip = flip

        self.front = str(frontSource)
        self.back = str(backSource)

    def on_press(self):
        if not self.flip:
            self.source = self.front
            self.flip = True
            if self.board.count % 3 == 1:
                self.board.SecondAdd = str(self.source)
                self.board.count += 1
            if self.board.count % 3 == 0:
                self.board.firstAdd = str(self.source)
                print(self.board.lastAdd)
                self.board.count += 1


class TestApp(App):
    def build(self):
        self.title = 'game'
        return Board()


TestApp().run()
I get this error:
Error:
File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch File "C:/Users/benya/NewZikaronGame.py", line 128, in on_press if self.board.count % 3 == 1: AttributeError: 'int' object has no attribute 'count' libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile
Please help me figure out what the problem is