Discuss Scratch
- MI5TER2000
-
Scratcher
22 posts
Scratch blocks to Python.
Put scratch blocks in, then say what they would be in python.
- DeletedRohizzle
-
New Scratcher
20 posts
Scratch blocks to Python.
Try posting this in the suggestions directory
- s200860
-
Scratcher
15 posts
Scratch blocks to Python.
(pick random (1) to (10))from random import randint
randint(1, 10)
- Steve0Greatness
-
Scratcher
1000+ posts
Scratch blocks to Python.
Try posting this in the suggestions directoryI don't think this is a suggestion
- MI5TER2000
-
Scratcher
22 posts
Scratch blocks to Python.
ask [What’s your name?] and waitinput(What’s your name?)
- BigNate469
-
Scratcher
1000+ posts
Scratch blocks to Python.
Try posting this in the suggestions directoryThis topic isn't a suggestion; it's a topic where people share what scratch blocks would be if they were written in Python.
You can use the [code] and [/code] tags to highlight your code. For example,
print("hello")
[code=python] print("hello") [/code]
Last edited by BigNate469 (July 29, 2024 21:00:02)
- SpyCoderX
-
Scratcher
1000+ posts
Scratch blocks to Python.
Sprites would probably be instances of a class like this:
As would costumes.
class Sprite: _position = [0,0] _size = 1.0 _direction = 0 _name: String _costumes = [] _current_costume = 0 #The index of the current costume def __init__(self,name: String): self._name = name def x_position(self): return self._position[0] def y_position(self): return self._position[1] def size(self): return self._size def name(self): return self._name def direction(self): return self._direction def costume_index(self): return self._current_costume # Getters are above # Setters are below def set_x_position(self,new_x:float): self._position[0] = new_x def set_y_position(self,new_y:float): self._position[1] = new_y def set_size(self,new_size:float): self._size = new_size def set_direction(self,new_direction:float): self._direction = new_direction def set_costume_index(self,new_index): self._current_costume = new_index
Last edited by SpyCoderX (July 30, 2024 02:57:06)
- gilbert_given_189
-
Scratcher
1000+ posts
Scratch blocks to Python.
Sprites would probably be instances of a class like this:Could be made better with the @property decorator:As would costumes.class Sprite: _position = [0,0] _size = 1.0 _direction = 0 _name: str _costumes = [] _current_costume = 0 #The index of the current costume def __init__(self,name: String): self._name = name def x_position(self): return self._position[0] def y_position(self): return self._position[1] def size(self): return self._size def name(self): return self._name def direction(self): return self._direction def costume_index(self): return self._current_costume # Getters are above # Setters are below def set_x_position(self,new_x:float): self._position[0] = new_x def set_y_position(self,new_y:float): self._position[1] = new_y def set_size(self,new_size:float): self._size = new_size def set_direction(self,new_direction:float): self._direction = new_direction def set_costume_index(self,new_index): self._current_costume = new_index
class Sprite: _position = [0.0,0.0] _size = 1.0 _direction = 0 _name: String _costumes = [] _current_costume = 0 # The index of the current costume def __init__(self, name: str): self._name = name @property def x_position(self) -> float: return self._position[0] @x_position.setter def x_position(self, value) -> float: self._position[0] = value @property def y_position(self) -> float: return self._position[1] @y_position.setter def y_position(self, value) -> float: self._position[1] = value @property def size(self) -> float: return self._size @size.setter def size(self, value) -> float: self._size = value @property def name(self) -> str: return self.name @property def direction(self) -> float: return self._direction @direction.setter def direction(self, value) -> float: self._direction = value @property def costume_index(self) -> int: return self._costume_index @costume_index.setter def costume_index(self, value) -> int: self.costume_index = value
Last edited by gilbert_given_189 (July 30, 2024 03:13:53)
- MI5TER2000
-
Scratcher
22 posts
Scratch blocks to Python.
add [Hello World] to [List]
List = List + “Hello World”
- TheCreatorOfUnTV
-
Scratcher
1000+ posts
Scratch blocks to Python.
import turtle
pen up
turtle.up()
pen down
turtle.down()
go to x: () y: ()
turtle.goto(x, y)
set pen size to ()
turtle.width(size)
start fill :: pen // This isn't a real block
turtle.begin_fill()
end fill :: pen // Same comment as the last.
turtle.end_fill()
- gilbert_given_189
-
Scratcher
1000+ posts
Scratch blocks to Python.
add [Hello World] to [List]List = List + “Hello World”
Traceback (most recent call last):
File ".code.tio", line 1, in <module>
List = List + "Hello, world"
TypeError: can only concatenate list (not "str") to list
- PolandballLover
-
Scratcher
14 posts
Scratch blocks to Python.
((100) + (100))is
print(100 + 100)
Last edited by PolandballLover (Jan. 27, 2025 12:05:16)
- superbluigi
-
Scratcher
100+ posts
Scratch blocks to Python.
say [Hello World!] for (2) secs
import time
print("Hello World!")
time.sleep(10)
- imfh
-
Scratcher
1000+ posts
Scratch blocks to Python.
My sb3topy program converts most blocks to something in Python. https://scratch.mit.edu/discuss/topic/600562/
Edit: Here's some code it made. I tried to include more, but the filter didn't like something in it and I'm didn't figure out what it was.
Edit: Here's some code it made. I tried to include more, but the filter didn't like something in it and I'm didn't figure out what it was.
import engine from engine.events import * from engine.operators import * from engine.types import * @sprite('Sprite1') class Sprite1(Target): """Sprite Sprite1""" @on_green_flag async def green_flag(self, util): while True: await self.glideto(util, 1, "Soccer Ball") await self.sleep(3) await self.yield_() @sprite('Soccer Ball') class SpriteSoccerBall(Target): """Sprite Soccer Ball""" @on_green_flag async def green_flag(self, util): while True: while not util.inputs["space"]: await self.yield_() while not not util.inputs["space"]: await self.yield_() self.goto(util, "_mouse_") await self.yield_() if __name__ == '__main__': engine.start_program()
Last edited by imfh (Jan. 29, 2025 03:22:09)
- hacktronics
-
Scratcher
100+ posts
Scratch blocks to Python.
We have some implementation to control Scratch sprite using Python. Here is the documentation and example, if anyone is interested.
https://codeskool.cc/codeskool-scratch-python-classes-documentation/
https://codeskool.cc/codeskool-scratch-python-classes-documentation/
- wikhar
-
Scratcher
2 posts
Scratch blocks to Python.
a = “hallo”
print(a)
print(a)
set [ a] to [hello]
say (a)
Last edited by wikhar (Oct. 11, 2025 12:34:55)













