Character Control using Python - 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/.

Related

How can I use multiple keys to do one thing in turtle

I am pretty much a beginner at Python and code altogether. I have a raspberry pi to mess around on and I recently got a Trilobot.
I'm trying to set it up so I can control it with a keyboard. I decided to use turtle and have been using things like the code below. I want to be able to go forward and right, but I don't know how to do both of them at the same time by holding w and d.
def forward():
Bot.forward()
wn.onkeypress(forward, “w”)
I don't know if any of that made sense. If it didn't, I'll gladly explain myself to get an answer.

How to make games that use graphic instead of text?

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 :)

Is there a way I can use Python to control the size and position of a Mac Window?

Generally I want to write a program to run in the background on Mac and when I push a keyboard shortcut, the current active window would be resized and positioned to the way I have set.
Something similar to the tool called SizeUp on Mac. I think this shouldn't be difficult to implement and would be fun to take a try.
I would appreciate any resources you could point me to. Thanks.
I think you're going to have an easier time attacking this in applescript. Upon casual googling, this link seems to have more or less what you want. If you were more looking for a programming challenge in python, and less for a solution, then disregard this.

Adding wxPython GUI elements in a pygame physics simulation

I have made a pygame physics simulation--'a projectile motion' but it lacks interactivity like accepting angle of launch,speed etc. I am wanting to add input boxes with increase decrease arrows but don't know how to go about it. Thanks for the help.
Maybe you can try PGU (Phil's pyGame Utilities).
In addition to other tools, it has a library for creating GUIs.
This PGU demo shows probably something similar to that you are looking for:
Try Some of these:
http://wiki.wxpython.org/IntegratingPyGame
http://www.pygame.org/project-Pygame+embedded+in+wxPython-1580-2788.html
Good luck!
I don't think trying to add wx-Elements is a very pygame way of implementing a GUI, a better (in sense of portable) way would be to use some all-in-python-GUI-extention for pygame. But the issue of GUI in pygame is anoying, since I could not find any library that offeres such a thing.
I know of two interesting approches, first there is Albow (a little bit of widgetry for pygame), which has a nice implementation of styles. The newest Version (which is not very new, I'm afraid) can be found at http://www.cosc.canterbury.ac.nz/greg.ewing/python/Albow/
Then there is OcempGUI http://ocemp.sourceforge.net/gui.html -- which has documentation and an some good concepts of event handling.
The sad thing is, both projects seem to be dead. I know of no other pygame-GUI that is worth looking at (correct my on that one, please!). For my own project I started to build something inspired by both of them (just don't expect that to ever become useable), since I'm not really content with either of the two. But they might by just the thing if you don't want to put too much time into it and want to have a good collection of GUI elements from labels and buttons up to file browsing dialogs or scrollable text fields.

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