0
\$\begingroup\$

I've been making a text-based RPG in Python, and I'm a bit lost in transitioning from a console to a window.

I'm not trying to do anything fancy (I think). I'd like my text to display normally, as it would in the console.

This is a good example: http://inventwithpython.com/blogstatic/esotera.png?27f655

However, I'd like to load images so that my different locations have corresponding backgrounds (I.e. When the character enters a tavern, the background is a tavern).

I have Pygame installed, but I really have no idea where to go from here, and I can't find any tutorials for text-based games like this.

My game code is here if you'd like to take a look:

https://gist.github.com/NervousTumbleweed/f42f326982f2af1549b528ce0156e34a

\$\endgroup\$
1
\$\begingroup\$

You can use Python's pygame library, which is used to make video games, and handles GUI as well. Here's a small example (Nerd Paradise PyGame Tutorial):

import pygame

pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False

while not done:
        for event in pygame.event.get():
                if event.type == pygame.QUIT:
                        done = True

        pygame.display.flip()

Using this example, you can create your own window, and draw graphics into it. To draw a simple rectangle you use

pygame.draw.rect(screen, (0, 128, 255), pygame.Rect(30, 30, 60, 60))

Once you get used to it, you can learn how to draw Sprites and text and complete something similar to the screenshot you provided, including images as background. Take a look at Nerd Paradise's tutorial for more in-depth of pygame and what you can do with it.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.