jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

only running when minimized #270

Open Ellgrey opened 5 years ago

Ellgrey commented 5 years ago

I am trying to make a clock in processing with python. The problem I am facing is that my program only runs when it is minimized. Here it is:

defining time

def time(): #time() makes clock run every second# x = 1 while x == 1: h = hour() m = minute() s = second()

    #colons#
    fill(0)
    textSize(120)
    text(":",120,100)
    text(":",260,100)

    #hour,minute,second#
    textSize(100)
    text(h,1,100)
    text(m,150,100)
    text(s,300,100)

def setup():

page

background(255)
size(1300,800)

def draw():
time()

Xevion commented 5 years ago

I'm unsure of why it updates whenever you minimize this, but if I'm correct, it's because you haven't exited the time() loop.

You need to call time(), wait a second through whatever method you wish, and have the draw() function exit.

The reason your code isn't running properly is because you have a while loop that isn't going to ever be exited. You're drawing the text over and over, but since text() is still "in progress", draw() is still "in progress" too, and thus, the program is waiting until they are both done to update the screen.

I've edited your code slightly to do four new things: 1) Instead of using a while loop, it'll just execute every time it draws (which is dictated by the frameRate variable, set by frameRate(#). 2) I've added a background(255) command as your text was overlapping. This time, it'll reset the background and redraw the entire thing. 3) I've added a time.sleep(1) command so that it'll only draw every second (the only time it'll ever need to draw.

import time

#defining time#
def time(): #time() makes clock run every second#
    h = hour()
    m = minute()
    s = second()

    #colons#
    fill(0)
    textSize(120)
    text(":",120,100)
    text(":",260,100)

    #hour,minute,second#
    textSize(100)
    text(h,1,100)
    text(m,150,100)
    text(s,300,100)

def setup():
    background(255)
    size(1300,800)

def draw():
    background(255)
    time.sleep(1)
    time()