NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Everything Else » Python programming help

June 21, 2011
by grombletromble
grombletromble's Avatar

Hello all, I'm very new to Python but I wanted to try it out on a project I've been planning for a while - I want to create a very basic sunrise alarm clock that essentially starts as a black screen and then gets progressively lighter until it is at full brightness at which point a sound would play if it had not already woken up.

Now I've been able to get a fullscreen colour, but I can't get it to refresh to a new colour :(

Would any Python buffs be able to tell me where I'm going wrong in refreshing the panel? Code:

!/usr/bin/python

keyevent.py

import wx,time

a = 0

class KeyEvent(wx.Frame): def init(self, parent, id, title): wx.Frame.init(self, parent, id, title)

    panel = wx.Panel(self, -1)
    panel.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
    panel.SetFocus()
    global a 
    self.SetBackgroundColour((a,a,a))
    self.ShowFullScreen(True)
    while(a < 255):
        a = a + 1
        self.SetBackgroundColour((a,a,a))
        self.Refresh()
        time.sleep(0.01)

def OnKeyDown(self, event):
    keycode = event.GetKeyCode()
    if keycode == wx.WXK_ESCAPE:
        self.Close()
    event.Skip()

app = wx.App() KeyEvent(None, -1, 'keyevent.py') app.MainLoop()

June 21, 2011
by missle3944
missle3944's Avatar

Hi grombletromble,

I too am working on a graphical program in python but I reccommend downloading and installing pygame. The nerdkits guys use it in alot of their projects that involve graphs. It is really usable and I got the basics of it in about an hour just of youtube. Here is the code for putting a white backround in python with pygame:

import serial
import sys
import os
import pygame, sys
import math

pygame.init()

#create the screen
screen = pygame.display.set_mode((640, 480),0,32)
white = (255,255,255)
screen.fill(white)

-missle3944

Post a Reply

Please log in to post a reply.

Did you know that you can build a circuit to convert the "dit" and "dah" of Morse code back into letters automatically? Learn more...