Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » [v1.3-beta] sb3topy: Scratch to Python with Pygame
- MagicCrayon9342
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
sb3topytoexe?
- imfh
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
Yeah you could probably convert it to an exe fairly easily. I had plans to include a built in export as exe option, but it ended up being low priority. I’ll put it back on the todo list. sb3topytoexe?
- AXEstudios
-
100+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
Someone finally made it
- lookupforcheese
-
3 posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
This looks like a neat idea, and I would like to wish you the best of luck on this project. 

- DifferentDance8
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
Like this person said, python to scratch would be far better. Considering that you should be able to plop in pygame code to turn into scratch code.Wow!!!!
Now do python to scratch, lol
- imfh
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
Python to Scratch is far more difficult because Python has more features than Scratch. In Python, you can create variables on the fly. How would you do that in Scratch? Pygame can also draw just parts of images and draw on images. You can’t do either of those to costumes with Scratch. In Python, you can also do stuff like open files and read JSON data from them.Like this person said, python to scratch would be far better. Considering that you should be able to plop in pygame code to turn into scratch code.Wow!!!!
Now do python to scratch, lol
I guess you could make a converter which just doesn’t work if you use any feature which isn’t in Scratch, but then it would fail for pretty much every Pygame project unless you specifically wrote it in a special way which doesn’t use any unsupported features.
- scratchniceperson
-
100+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
How scratch can do python coding, scratch is for block coding??
- bloctans_4
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
this is really cool
im also making a virtual machine/emulator for scratch. and block inputs/fields have been the hard part, how did you do it?
im also making a virtual machine/emulator for scratch. and block inputs/fields have been the hard part, how did you do it?
- imfh
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
This actually converts the project, so it's not exactly a vm/emulator. The way I handle inputs/fields is probably very different from how you need to. this is really cool
im also making a virtual machine/emulator for scratch. and block inputs/fields have been the hard part, how did you do it?
I go through each of the field / inputs for the block, and I save them in a dictionary along with their type. For example, field, block, literal, variable. Fields are always just “field”. Inputs can have a variety of types, and I base the type on the number with the input (see here).
Once I have the inputs/fields and their types, I cast them to the type I expect them to be based on a map. For example, the “change variable by” block expects a variable name and a number. If an input is a block/variable, I put a “cast wrapper” around the code generated by the block, for example “int( … )”. I only put the wrapper if the block's return type is not the expect type.
- scratchniceperson
-
100+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
(#27)Scratch can't do “Python coding”, this tool is a Python program that converts Scratch projects to Python programs. This is not a Scratch project.
How scratch can do python coding, scratch is for block coding??
Thanks for telling
- bloctans_4
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
in speaking of how you did things, heres another thing im always banging my head on:This actually converts the project, so it's not exactly a vm/emulator. The way I handle inputs/fields is probably very different from how you need to. this is really cool
im also making a virtual machine/emulator for scratch. and block inputs/fields have been the hard part, how did you do it?
I go through each of the field / inputs for the block, and I save them in a dictionary along with their type. For example, field, block, literal, variable. Fields are always just “field”. Inputs can have a variety of types, and I base the type on the number with the input (see here).
Once I have the inputs/fields and their types, I cast them to the type I expect them to be based on a map. For example, the “change variable by” block expects a variable name and a number. If an input is a block/variable, I put a “cast wrapper” around the code generated by the block, for example “int( … )”. I only put the wrapper if the block's return type is not the expect type.
- does your program properly center sprites
- and in the case it does, how the heck do you do it
Last edited by bloctans_4 (Aug. 17, 2022 18:52:02)
- bloctans_4
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
also, just tested out the program, doesnt pygame support svg now?
also it wont detect cairosvg
also it wont detect cairosvg
Last edited by bloctans_4 (Aug. 17, 2022 19:38:29)
- imfh
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
Yes, it does. Here's pseudo code showing how I do it: in speaking of how you did things, heres another thing im always banging my head on:
- does your program properly center sprites
- and in the case it does, how the heck do you do it
center = image.get_size() / 2 offset = Vector2(bitmapResolutionX, bitmapResolutionY) offset = (center - offset) / bitmapResolution offset = offset * costume_size/100 offset = offset.rotate(direction - 90) rect = image.get_rect( center = offset + Vector2(x_pos + 240, 180 - y_pos))
Relevant code:
Getting the center and scale
Initial offset calculations
Final rectangle calculations
Oh wow, it does! I'll have to make an update to use it. Yeah, installing CairoSVG properly is pretty difficult. It's one of the biggest flaws of the program. also, just tested out the program, doesnt pygame support svg now?
also it wont detect cairosvg
- bloctans_4
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
so as a performance test i ran https://scratch-mit-edu.ezproxyberklee.flo.org/projects/659120206/ through the converter, and the results are:
the converting assets stage used up all my cpu
the actual project used all my memory
the project cant run in 1920x1080
the converting assets stage used up all my cpu
the actual project used all my memory
the project cant run in 1920x1080
- bloctans_4
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
that is probably all pygame's fault
- bloctans_4
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame

i feel like this would be too hard to fix
- bloctans_4
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
another error with griffpatches gd: ERROR:root:Error in gathered task ‘<Task finished name=’Task-143' coro=<Spritemenu.broadcast_menuin1() done, defined at D:\sb3topy-1.1-beta\sb3topy-1.1-beta\outputs\project.py:2883> exception=NameError(“name ‘co nfig’ is not defined”)>'
Traceback (most recent call last):
File “D:\sb3topy-1.1-beta\sb3topy-1.1-beta\outputs\engine\util.py”, line 170, in _handle_tasks
task.result()
File “D:\sb3topy-1.1-beta\sb3topy-1.1-beta\outputs\project.py”, line 2898, in broadcast_menuin1
await util.sprites.broadcast_getrank(util)
File “D:\sb3topy-1.1-beta\sb3topy-1.1-beta\outputs\project.py”, line 3377, in broadcast_getrank
await self.my_TexttoNumber(util, config.USERNAME)
NameError: name ‘config’ is not defined
Traceback (most recent call last):
File “D:\sb3topy-1.1-beta\sb3topy-1.1-beta\outputs\engine\util.py”, line 170, in _handle_tasks
task.result()
File “D:\sb3topy-1.1-beta\sb3topy-1.1-beta\outputs\project.py”, line 2898, in broadcast_menuin1
await util.sprites.broadcast_getrank(util)
File “D:\sb3topy-1.1-beta\sb3topy-1.1-beta\outputs\project.py”, line 3377, in broadcast_getrank
await self.my_TexttoNumber(util, config.USERNAME)
NameError: name ‘config’ is not defined
- bloctans_4
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame

how did you fix this?
- imfh
-
1000+ posts
[v1.3-beta] sb3topy: Scratch to Python with Pygame
https://scratch-mit-edu.ezproxyberklee.flo.org/projects/659120206/ through the converter, and the results are:Hmm, yeah that seems like a stress test of the asset conversion. so as a performance test i ran
the converting assets stage used up all my cpu
the actual project used all my memory
the project cant run in 1920x1080
https://mv-ezproxy-com.ezproxyberklee.flo.org/get_image/.%2E/38373c8c5c08f9f4e7ae8b90e6e2dc40.pngNot necessarily… The colors are probably not too hard to fix. The positioning might be a bit harder though.
i feel like this would be too hard to fix
It looks like the username block is broken. I'm not sure how that missed testing. It's an easy fix though. another error with griffpatches gd: ERROR:root:Error in gathered task ‘<Task finished name=’Task-143' coro=<Spritemenu.broadcast_menuin1() done, defined at D:\sb3topy-1.1-beta\sb3topy-1.1-beta\outputs\project.py:2883> exception=NameError(“name ‘co nfig’ is not defined”)>'
Traceback (most recent call last):
File “D:\sb3topy-1.1-beta\sb3topy-1.1-beta\outputs\engine\util.py”, line 170, in _handle_tasks
task.result()
File “D:\sb3topy-1.1-beta\sb3topy-1.1-beta\outputs\project.py”, line 2898, in broadcast_menuin1
await util.sprites.broadcast_getrank(util)
File “D:\sb3topy-1.1-beta\sb3topy-1.1-beta\outputs\project.py”, line 3377, in broadcast_getrank
await self.my_TexttoNumber(util, config.USERNAME)
NameError: name ‘config’ is not defined
https://mv-ezproxy-com.ezproxyberklee.flo.org/get_image/.%2E/2129bf83add22918656df9391f6e092d.pngFix what?
how did you fix this?
Last edited by imfh (Aug. 21, 2022 18:17:46)
- Discussion Forums
- » Advanced Topics
-
» [v1.3-beta] sb3topy: Scratch to Python with Pygame