Jump to content

Converting a CLI game to GUI ...

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
parabalas

parabalas

    Newbie

  • Members
  • Pip
  • 1 posts
I haven't been programing long and I'm in a little bit of a fog. I wrote a simple word guessing game for my daughter in Python which we use through the command line interface. At 4 she's not too keen on the keyboard so I thought about turning this into a GUI. I've used Tkinter in very basic ways, building a calculator for example. What I have in mind is a GUI with an on-screen keyboard (which I've created with a loop) and have her use the mouse to click the letter. Now that last part will take a lot of work but I'm wondering if anyone out there has any thoughts on how I should best implement the following code into the GUI.

Many thanks,
Tom Perry,


#Julie's word game

import random


option = 1

EXIT_OPTION = 2

MAX_TURNS = 5


option = 0


# Retrieve data dictionary from data file

list_of_words = ["cat","dog","house", "boat", "bucket", "apple", "orange"]



# Generate random number to select category element

random_number = random.randrange(1,len(list_of_words) - 1)


# Select random word from dictionary

word = list_of_words[random_number].upper()


# Initialize clue letter list

clue = []


# Build clue list of letter spaces

for each_character in word:

    if each_character != " ":

        clue.append("_")

    else:

        clue.append(" ")


# Initialize number of turns

turns_remaining = MAX_TURNS


# Initialize list of guessed letters

guessed_letters = []


# Game Loop

while turns_remaining > 0:


    


    # Display clue to user

    for each_letter in clue:

        print each_letter,


    # Prompt user for letter guess & capitalize

    guess = raw_input("\n\nLetter ("+ str(turns_remaining) + ")? ")

    guess = guess.upper()


    # Process valid guess

    if guess not in guessed_letters:


        # Add guess to list of guesses

        guessed_letters.append(guess)


        # Initialize guess boolean

        allow_guess = False

        

        # Check for a match 

        for i in range(len(clue)):


            # Fill in clue if it is (& set guess boolean)

            if guess == word[i]:

                clue[i] = guess

                allow_guess = True


        # Allow user to solve if letter exists in word

        if allow_guess:


            

            for each_letter in clue:

                print each_letter,

            solution = raw_input("\n\nSolve? ").upper()

            if solution == word:

                print "\nCongratulations!"

                

                turns_remaining = 0


        # Inform user guess was not in word name

        else:


            print "\nSorry '" + guess.upper() + "' not in word!"

            


    # Otherwise inform user

    else:

        raw_input("\nLetter already used! <ENTER> to continue...")


    turns_remaining -= 1


    # Check for loser

    if turns_remaining == 0:

        print "\nSorry - you lose!"




#2
Sky

Sky

    Learning Programmer

  • Members
  • PipPipPip
  • 83 posts
You can use On-Screen Keyboard in Windows to type in CLI. Is that what you are wondering about?

I was trying to read the code, but I don't know why do you declared option=1 and then assign it 0, option = 0?

#3
Excited

Excited

    Newbie

  • Members
  • PipPip
  • 27 posts
I suggest PyQt PyQt - PythonInfo Wiki