Archived posts, use them to search

Re: VPL: How to run a graphical tkinter (Python) program

by Smita Shrivastava -
Number of replies: 3

Hi Juan Carlos,

Sorry for writing again. I wanted to share with you what I'm trying to do in case there is a workaround before the next release of VPL comes out.

I am using the Python turtle module and I am trying to take user input from the console using the input() function. I am seeing this error at the line where the input() function is called: 'EOFError: EOF when reading a line'.
 
I am able to take user inputs when I am not using turtle functions in my code and I don't have Tkinter as a comment in the code. 
I am also able to use the turtle module without taking user inputs and I am able to see turtle output on the GUI. It is just that when I combine both (input from console and turtle output on GUI) that I see this error. In order to get the turtle output on the GUI, I have added #Tkinter as a comment.

I also tried moving the input() function before and after the turtle function call and I see the same error in both scenarios.

I wanted to find out if there is a script that I need to add to enable taking user inputs for turtle module in Python.

Would greatly appreciate your help and inputs.

Best regards
Smita Shrivastava

In reply to Smita Shrivastava

Re: VPL: How to run a graphical tkinter (Python) program

by Juan Carlos Rodríguez-del-Pino -
Picture of Particularly helpful Moodlers Picture of Plugin developers

By default, VPL does not offer this feature. VPL does not allow console iteration when running Python with GUI.
If you want this behavior, you must set the following script at "advanced features->execution files->vpl_run.sh" file.

#!/bin/bash
# This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
# Script for running Python language
# Copyright (C) 2014 onwards Juan Carlos Rodríguez-del-Pino
# License http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
# Author Juan Carlos Rodríguez-del-Pino <jcrodriguez@dis.ulpgc.es>

# @vpl_script_description Using python3 with the first file
# load common script and check programs
. common_script.sh
check_program python3
get_first_source_file py
cat common_script.sh > vpl_execution
echo "export TERM=ansi" >>vpl_execution
echo "python3 \"$FIRST_SOURCE_FILE\"" >>vpl_execution
chmod +x vpl_execution
mv vpl_execution console_execution
get_source_files py
check_program x-terminal-emulator xterm
cat common_script.sh > vpl_execution
echo "$PROGRAM -e ./console_execution" >> vpl_execution
echo "sleep 5s" >> vpl_execution
echo "wait_end console_execution" >> vpl_execution
mv vpl_execution vpl_wexecution

Best regards,

Juan Carlos.

In reply to Juan Carlos Rodríguez-del-Pino

Re: VPL: How to run a graphical tkinter (Python) program

by Smita Shrivastava -

Hi Juan Carlos,

Thank you very much! I have added this script and I am now able to take user input and pass the input to turtle functions. I had a few more questions related to this -
1) In case of an error, I don't see an error message on the console anymore. Is there a way to enable this?
2) The UI closes immediately after the code is executed. I have currently added sleep() at the end of the code in order to see the output on the UI. Is there a way to make the UI stay a little longer so that the output could be observed without adding sleep().
3) Is there a way to set the screen size and location for the console as well as the UI?

I also had a question on the image formats that are supported -
4) I am trying to add a shape to the turtle using turtle.shape(imagename) and I am able to add .gif images but not other formats. Is there a restriction on the image format that could be used in VPL?

I also had a question on Input for Java programs -
5) I am doing a similar exercise in Java where I am taking user input and using it on the UI. For this I am currently using javax.swing.JOptionPane to take user inputs. Is there a similar script that I can use to take user inputs via console and use it for output on the UI?

Thank you again for your help!

Best Regards
Smita Shrivastava

In reply to Smita Shrivastava

Re: VPL: How to run a graphical tkinter (Python) program

by Juan Carlos Rodríguez-del-Pino -
Picture of Particularly helpful Moodlers Picture of Plugin developers

I will try to answer your questions:
A1) You can add a "read" command to wait for the "return key"
echo "read"" >>vpl_execution
add after  "echo python3 ...
A2) I think that this issue about programming and not related to VPL or the custom script.
A3) Sorry, but I don't know.
A4) No. VPL manages as binary the image files with the following file extensions: gif, jpg, jpeg, png, ico. The use of these files programmatically is not related to VPL.
A5) No, I don't have a similar solution for Java. Notice that I have a specific script to resolve your problem with Python because a colleague had the same problem, and I wrote the script for him. We are planning to develop a global solution but not yet done.

best regards,
Juan Carlos.