I take it if I just want a square I would get rid of the other
elements on the checkbox?? and then remove other feature I didn't
want in it.. I have been torturing myself in pygame trying to do it.
widgets are not my thingl... it almost works though sorry that it is
off the target library of pyglet.. I would be glad to port it over if
I can understand how it could work..
import pygame
#from pygame.color import THECOLORS
pygame.init()
screen = pygame.display.set_mode((640,480))
#pygame.display.update()
#use this to update the screen
class recttoggle:
def __init__(self):
self.state = '0'
self.x = 0
self.width = 0
def setforgroundcolor(self,color):
"set the clicked color of the widget"
self.forgroundcolor = color
def setbackgroundcolor(self,color):
"set the original color of the widget"
self.backgroundcolor = color
def draw(self, screen, (x,y, width, height), thickness):# ,
#thickness and passes in vars):
"This draws the widget in it's original unclicked state and passes
in variables"
self.screen = screen
self.x = x
self.y = y
self.width = width
self.height = height
pygame.draw.rect(self.screen, self.backgroundcolor,
(self.x,self.y, self.width, self.height), thickness)
self.state == '1'
self.thickness = thickness
def redraw(self):
"all the draws after the startup have to check what the state is"
if self.state == '1':
pygame.draw.rect(self.screen, self.setforgroundcolor,
(self.x,self.y, self.width, self.height), self.thickness)
self.state = '0'
if self.state == '0':
pygame.draw.rect(self.screen, self.backgroundcolor,
(self.x,self.y, self.width, self.height), self.thickness)
self.state = '1'
def checkclick(self,x,y):
"check a x, y value to see if it is in the rectangle"
if x > self.x:
if x < self.x + self.width:
if y > self.y:
if y < (self.y + self.height ):
self.redraw()
testrect = recttoggle()
volor = pygame.color.Color("green")
testrect.setbackgroundcolor(volor)
volor = pygame.color.Color("yellow")
testrect.setforgroundcolor(volor)
testrect.draw(screen, (20, 20, 10, 10), 2)
#A - Assign values to key variables
clock = pygame.time.Clock()
keepGoing = True
#L - Set up main loop
while keepGoing:
#T - Timer to set frame rate
clock.tick(30)
#E - Event handling
for event in pygame.event.get():
testrect.checkclick(pygame.mouse.get_pos())
print pygame.mouse.get_pos()
if event.type == pygame.QUIT:
keepGoing = False
elif event.type == pygame.MOUSEBUTTONDOWN:
testrect.checkclick(pygame.mouse.get_pos())
print pygame.mouse.get_pos()
#pygame.display.update()
#R - Refresh display
#screen.blit(screen, (0,0))
#screen.blit(image, (250, 150))
#screen.blit(image, (0,0))
pygame.display.flip()
On May 23, 1:08 pm, Tristam MacDonald <[email protected]> wrote:
> Today brings the 1.0.1 release, with the addition of a slider control,
> improved documentation, and several bug fixes.
> Check it out
> here<http://swiftcoder.wordpress.com/2009/05/23/simplui-1-0-1-released/>
> .
>
> I could do with feedback on the API, so if you take it for a spin, please
> let me know your thoughts.
>
> On Thu, May 21, 2009 at 8:10 AM, Tristam MacDonald
> <[email protected]>wrote:
>
> > simplui (pronounced 'simply') is a pyglet GUI toolkit for rapid prototyping
> > and development.
> > This is a very early release, but perfectly useable, check it out
> > here<http://tr.im/lXi5>
> > .
>
> --
> Tristam MacDonaldhttp://swiftcoder.wordpress.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---