How to make games that use graphic instead of text? - python

Hi I was wondering if anyone could answer my question, how would I go about making a game with graphics in python instead of text based games.
I'm only new though so if it involves another programming language then I'm probably can't do it yet.

Use tkinter module inside of python. To do this simply add from tkinter import * at the start of your program and open a window and use a mainloop to close it at the end. You can research how to use tkinter online on various different websites. I would suggest effbot as it's very useful for tkinter basics.

I would recommend using the tkinter library. You can makes games with graphics instead of text. One example would be here. And it is just Python :)

Related

Importing tkinter modules

Is it possible to just import parts of tkinter, like you can import parts of Java swing without having to import the entire library when you only need to use 4 or 5 modules. I am writing small python program with pop-up input/output window a few textboxes and buttons and only want to use grid layout manager.
I have looked through all the python and tkinter documentation and searched tutorial websites and youtube unable to find an example.
General python/tkinter language query.
You have to have all of tkinter in memory even if you don't use it all. You can import individual pieces like you can with any other python module, but that won't make your program any smaller or more efficient. Under the hood python will import the entire module, even if it only makes part of the module visible to your code.
Arguably, the only real effect would be in making your code a bit harder to understand by deviating from best practices.

How to accept text input from a pygame GUI

I am working on a RPG game using Python and Pygame, and am trying to make a two-part GUI, including a lower part that is like the basic command line, and a top part that will show all graphical "action."
What I need to find out is a way to include both in a pygame window, instead of using a pygame window and terminal window. As well, are there any Pygame GUI toolkits that would be appropriate for this use?
Thanks All!
May I suggest using ezText instead?
It's a cool way to add text inupt bars to pygame. I used it before my self, and It's really easy to use.
http://www.pygame.org/project-EzText-920-.html
(feel free to leave a comment if you want help using it, although everything you need to know is in the example.py that comes with it)
Take a look here (http://wiki.python.org/moin/PythonGameLibraries) for a whole list of ToolKits for both Pygame and Pyglet. Albow (http://www.cosc.canterbury.ac.nz/greg.ewing/python/Albow/) has worked well for me in the past.
The easiest way to accomplish what you're talking about would be to make two Surfaces, one for each part of the interface, and then constantly update them in separate modules to finally blit them every frame. That way your main module can be simplified to something like:
import action_gui
import cl_gui
import pygame
pygame.init()
MAIN_SURF = pygame.display.set_mode((x, y))
pygame.display.set_caption('My Game')
while (True):
action_surf = action_gui.update()
cl_surf = cl_gui.update()
MAIN_SURF.blit(action_surf, my_position_1)
MAIN_SURF.blit(cl_surf, my_position_2)
Best of luck.

Character Control using Python

I was wondering if anyone knows how to import a sprite and let it move when pressing the arrow keys in python, without using pygame, or some other library. This is purely out of curiosity, because I was just thinking about some sort of personal challenge, and that's what came to mind: a python game, without the help of pygame or libtcod. Is this possible, or do you need a library to do this for you? I'd appreciate anyone's input on this one.
Thanks.
What comes to my mind is using Tkinter's Canvas class. It is quite possible to do a simple program like that described using bindings on this class.
A good example of this may be found in Mark Lutz's Programming Python (http://shop.oreilly.com/product/9780596158118.do), the Moving Pics example.
If you don't own this, you can still look at the code for it as a reference by downloading the code using the link on the right side of the page. The path to the appropriat folder is /PP4E-Examples-1.3.1/Examples/PP4E/Gui/MovingPics/.

Tkinter Python Resources

I'm looking to design a (very) basic GUI for a battleship game.
As suggested in another question, I was going to use Tk's check buttons and coordinates and pass the value and so forth.
I'm having a tough time finding a decent start-up tutorial for Tkinter. I've tried Google and went through several results to little to no avail. Though I'm pretty experienced with Python, I've never done any GUI (other than lightly with Xcode). If anyone knows any good resources, I'd really appreciate it.
"Programming Python" by Mark Lutz has a chapter on GUI's.
The tkinter page on the Python wiki has links to tutorials as well.
tkdocs.com has a tutorial that covers tkinter (as well as using tk with Ruby, Perl and Tcl).
For what you need I suggest you look at the canvas widget
There are several resources: e.g. - http://www.techrepublic.com/article/tkinter-canvas-freeform-guis-in-python/6310698 or http://effbot.org/tkinterbook/canvas.htm

Text-based game graphics in Python

I'm pretty new to programming, and I'm creating a simple text-based game.>
I'm wondering if there is a simple way to create my own terminal-type window with which I can place coloured input etc.
Is there a graphics module well suited to this?
I'm using Mac, but I would like it to work on Windows as well
Thanks
The Tkinter Text Widget will do what you ask. the IDLE main window is implemented as one, if you want to play with an example.
You could use the termcolor library - it that what you're looking for?
On Windows things are trickier. See this SO answer - you should resort to win32console and some ctypes. The answer has some code and links to other articles.
For game programming with Python, I would always recommend PyGame.
It is not very complex and enables you to easily use input, graphics and sound.
As a start:
http://www.penzilla.net/tutorials/python/pygame/

Categories