[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Tutorial... GUI



On Wed, September 26, 2007 2:07 pm, RR4CLB wrote:
> I have asked about tutorials and a good explanation on how to place a
> button or radial button on a page and I can not seem to find a good
> explanation or location to clearly give those examples. I was given a
> reference to GUI's and that to was hard to figure out, especially for a
> blind user. The format is not very user friendly.

> I have loaded on my computer is Window OS version Python 2.5 and it has
> stuff on TK and TCL and I do know that the SDL commands work. It just
> does not tell me how to turn it on, the editors...

I'm not sure what you mean about turning things on. Are you able to get to
a Python programming environment (such as IDLE) at all, and run a "hello
world" program? Or is it that you can't get Pygame running?

Generally what you'd do to start using Pygame/SDL (Pygame is a sort of
wrapper around SDL) is to make sure you have Pygame installed, then at a
Python console or in a program type:
import python
python.init()
screen = pygame.display.set_mode((640,480)) ## Or another size

That should give you a window to start drawing in.

I don't know enough about the GUI needs of a blind user to advise you very
well; what kind of interface do you have in mind? Are you trying to draw a
graphical interface suitable for sighted users, or something very
different?

On the assumption that you're looking to make a simple GUI with ordinary
graphics, a straightforward way of doing that is:
-Create a Widget class that has a location (a Rect object) and a function
for drawing itself (say, a blue rectangle with a white border; you can do
this with pygame.draw.rect).
-Create some instances of this class, giving them locations and keeping a
list of them.
-In your program's main loop, when checking the various Pygame events, say
the following, probably only for MOUSEBUTTONDOWN events:
handled = False
for widget in my_widgets:
  handled = widget.HandleEvent(event) ## or just event.pos
  if handled:
    break
if not handled: ## Respond in some other way.
-Have the HandleEvent function compare the event.pos (the location of the
mouse click) to its own location, using the Pygame "collidepoint"
function. If the position is within the widget's borders, the button was
clicked on.

That's a quick and dirty way of doing a UI, or buttons anyway. In other
words you draw _something_ on the screen, then check whether any mouse
click was within its borders. I did a more elaborate GUI of my own, some
version of which you can find as the messy "Driftwood" code at
<http://kschnee.xepher.net/code/070530ShiningSeaSource.zip>.