how to use pythonGenerator at codepen.io?

105 views
Skip to first unread message

m lz

unread,
Mar 26, 2023, 12:14:47 PM3/26/23
to Blockly
I tried a lot of demo,finally make this work all very well ,only the custom block generator is not ok,bellow is my link,

I know I need use some code like this,but it not work under codepen.io
// import * as Blockly from 'blockly/core';
// import {pythonGenerator} from 'blockly/python';

// pythonGenerator['open_chrome3'] = function(block) {
//   // var value_name = pythonGenerator.valueToCode(block, 'URL', pythonGenerator.ORDER_ATOMIC);
//   // TODO: Assemble Python into code variable.
//   var code = `bbbbbbbb\n`;
//   return code;
// };
if I uncomment this code ,it will make a error

Maribeth Bottorff

unread,
Mar 27, 2023, 2:44:20 PM3/27/23
to Blockly
Hello,

Since you are loading Blockly using script tags you need to follow the instructions for cdn/local scripts shown here: https://developers.google.com/blockly/guides/configure/web/code-generators#unpkg

In other words, you need to use `Blockly.Python` instead of `pythonGenerator`. 

Good luck,
Maribeth

Mark Friedman

unread,
Mar 28, 2023, 2:47:49 PM3/28/23
to blo...@googlegroups.com
I believe that for CodePen you want to use the unpkg versions of the Blockly packages as shown in https://developers.google.com/blockly/guides/configure/web/code-generators#unpkg.  You would place the appropriate URLs in the "Add External Scripts/Pens" section of the CodePen settings form your pen.

Hope this helps.

-Mark

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/e8bd5254-408d-4b2d-bb8f-971347a5f9c3n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages