Ask coding questions

← Back to all posts
Background in python
AhmadAyyeh (6)

I am trying to add a background image in python but I cannot figure out how to do so, I am using python 3.0. I am new to programming :)

mwilki7 (1136)

I have put together driver code for a pygame application from stuff I found on the internet here:

[line 31] BackGround = Background('your_background_image_here.png', [0,0])
with whatever name your background image is.

You might need to resize the window:
[line 12] size = (700, 500)
so that your background image fits inside

AhmadAyyeh (6)

@mwilki7 Thanks a lot! But just a quick question, where should I type my code?
I have coded my whole program using functions so I only have to call for main() in order for the program to run.
Here's my program:

JustARatherRidi (214)

Hey, please share your repl so that we can help you out :)

AhmadAyyeh (6)

@JustARatherRidi here it is:
This is only a part of the program, I've been trying on this one because I didn't want to mess my project up.....if you want the whole code just let me know!

JustARatherRidi (214)

@AhmadAyyeh Okay, so it looks like both of your programs runs on the terminal (meaning that you print to the terminal and you get input from the terminal), and there really isn't any way to stick an image onto the terminal. All it can do is display characters.

But in your first program, it looks like you're trying to make a GUI using tkinter, which is what you should do if you really wanted to show that image.

How you would go about making a GUI in tkinter is by using textboxes instead of inputs and using a button to submit, and maybe lists or comboboxes if you want to make it look better.

If you decide that it is worth learning tkinter for the sake of the image, here's an answer that will help

Good luck!

AhmadAyyeh (6)

@JustARatherRidi Hello,
Thanks alot for your help, I kind of understood how to work with tkinter but I have another problem, whenever I run the program, for some reason it keeps showing soundex_code as p160 and cannot figure out how to fix it....
can you please help me figure it out? here's my code with tkinter:
and here's my original code:
(by the way, for some reason when I run the code on repl and press on get data it does not always output data (probably connection issues) but when I run it on IDLE on my desktop it works)
Thanks again!

PYer (4035)

You can't put an image in the terminal. Are you using flask, or something else?

AhmadAyyeh (6)

@PYer I'm only using python....