[Tutor] Python 3.7 Grids

David Merrick merrickdav at gmail.com
Sat Jun 29 02:12:46 EDT 2019


Hi Looking for a way to use the determine the position of a card in a grid
using the mouse click event in Python. Code is attached.

Unfortunately using Tinkter grids / frames can't determine between the two
demo cards.

The Relevant code is below

def showCardInitial(cardList):
    cardsToPlay = []
    length = len(cardList)

    fileFaceDown = 'extracards/FACEDOWN.gif'
    cardFaceDownCard = fileFaceDown.split('/')
    cardFaceDownCard = cardFaceDownCard[1].split('.')[0]
    photo = PhotoImage(file=fileFaceDown)
    number = random.randrange(0,length)
    fileFaceUp = cardList[number][2]
    card = fileFaceUp.split('/')
    card = card[1].split('.')[0]
    w = Label(image=photo)
    w.photo = photo
    w.grid(row = 0,column = 0,padx = 10)

    #print('cardListis ',cardList)

    cardFile = cardList[1][2]
    #print cardFile
    photo = PhotoImage(file=cardFile)
    cardToDisplay = Label(image=photo)
    cardToDisplay.photo = photo
    cardToDisplay.grid(row=0,column = 1,padx = 10)
    #w.grid(row = row,column = count)
return

def determineCard():
    global x
    global y
    print( "clicked at", x, y)
    if(2 <= x and x <= 83) and (0 <= y and y <= 130):
        print('Card One is Selected')
return

Any suggestions are welcome

-- 
Dave Merrick

TutorInvercargill

http://tutorinvercargill.co.nz

Daves Web Designs

Website http://www.daveswebdesigns.co.nz

Email merrickdav at gmail.com

Ph   03 216 2053

Cell 027 3089 169


More information about the Tutor mailing list