I started learning python a month and a half ago. So please forgive my lack of everything.
I'm making a text based adventure game. The game has been written and playable in terminal. I'm now adding a GUI as an after thought.
In one file, I have:
class Parser():
def __init__(self):
self.commands = CommandWords()
def get_command(self):
# Initialise word1 and word2 to <None>
word1 = None
word2 = None
input_line = input( "> " )
tokens = input_line.strip().split( " " )
if len( tokens ) > 0:
word1 = tokens[0]
if len( tokens ) > 1:
word2 = tokens[1]
This is called whenever the user is expected to enter text, it will then call another function to compare the input with known commands to move the game along.
However, when I tried to replace the input() with entry_widget.get(), it doesn't recognise entry_widget. so I imported my file containing the GUI script, which is a circular importing error.
I tried to store the input as a string variable, but the program doesn't stop and wait for the user input, so it gets stuck the moment the program start to run not knowing what to do with the empty variable. (that is assuming input() stops the program and wait for user input? )
Any solutions? Or better ways of doing this?
Thanks.