Closed hx2A closed 2 years ago
I'm currently trying to use `py5_tools.screenshot` in class mode, but I'm having trouble getting it to work, so any advice would be great!
from py5 import Sketch from py5_tools import screenshot from utils import get_timestamp class FirstSketch(Sketch): def settings(self): self.size(600, 600) def setup(self): self.rect_mode(self.CENTER) def draw(self): self.rect(self.mouse_x, self.mouse_y, 30, 30) def key_typed(self): if self.key == "s": time_stamp = get_timestamp() img = screenshot(sketch=self, hook_post_draw=True) img.save(f"{time_stamp}.png") def main(): sketch = FirstSketch() sketch.run_sketch() if __name__ == "__main__": main()
When typing s, got error output:
s
❯ python main.py py5 encountered an error in your code:File "C:\Users\zztkm\dev\sandbox\pydev\py5-example\main.py", line 20, in key_typed 17 def key_typed(self): 18 if self.key == "s": 19 time_stamp = get_timestamp() --> 20 img = screenshot(sketch=self, hook_post_draw=True) 21 img.save(f"{time_stamp}.png") .................................................. self = <__main__.FirstSketch object at 0x000002882B98BA90> .................................................. UnboundLocalError: local variable 'py5' referenced before assignment
Originally posted by @zztkm in https://github.com/py5coding/py5generator/discussions/170
Need to do two things:
screenshot()
save_frame()
Fixed by #172
When typing
s
, got error output:Originally posted by @zztkm in https://github.com/py5coding/py5generator/discussions/170