Smith Jr
Smith Jr

Reputation: 59

Am stuck on how to get my user to input their score

Basically I have created a game with users in pygame. I used a tkinter GUI for my login.

I have wrote the SQL part and it outputs my score when die to my database I used test number for my student number, I don't know how to get it so my user can enter their user ID and that is saved along with their score.

Can anyone help please?

Code:

def gameover():
    message = Msg("Game Over")
    message.update()
    player.kill()
    shot.kill()
    SQL = 'INSERT INTO TblScore(Score, StudentID) VALUES (' + str(score.value) + ', ' + str(8) + ')'
    Databaseconnector.INSERT(SQL)
    pygame.quit()

Upvotes: 1

Views: 105

Answers (2)

Pip
Pip

Reputation: 4457

(im not experienced with guis yet, but here's my guess)

you could either save their login id or say x = input('Enter your Login ID") then pull the id out of "x"

Upvotes: 0

Bartlomiej Lewandowski
Bartlomiej Lewandowski

Reputation: 11180

You could try something like this:

for event in pygame.event.get():
    if (event.type == pygame.KEYDOWN):
        if(event.key>= K_a && event.key <= K_z):
           s+=chr(event.key)

this will append the pressed key character to your string s.

Upvotes: 1

Related Questions