Python3 GUI (tk) questions

Python3 GUI (tk) questions

por Jin Hong -
Número de respuestas: 3

So I was looking into setting up some GUI questions using tk. I retrieved the question sample from the forum post (https://coderunner.org.nz/mod/forum/discuss.php?d=237#p990), imported it and ran it. but it threw me an error.

Basically, there is no output from running the sample answer. I couldn't really figure out why. 

Has there been some updates or have I set something wrong? Thanks!



En respuesta a Jin Hong

Re: Python3 GUI (tk) questions

por Richard Lobb -
Yes, sorry Jin. The prototype was an older variant that expected to take the GUI command sequence from the test's TEST.stdin field whereas the sample question has the commands in the TEST.extra.

I've updated the prototype on github so you could download that again or you could just replace the line

{{ TEST.stdin }}

in the prototype's template with

{{ TEST.extra }}
 
and save.
En respuesta a Richard Lobb

Re: Python3 GUI (tk) questions

por Jin Hong -
That worked the charm, thank you :)

I do have one other question, this may not be the coderunner issue but the way GUI code is written.

Currently, you have the get() method to print out "Calling 'get' on a widget is not supported. Please associate the widget with a textvariable and do a 'get' on that instead."

I have code samples that call the get methods on widgets. I think there are also different opinions online on whether to call "get" from the textvariable or from the widget.

I can get past this by overriding the get method on the child class (e.g., Combobox), but just wanted to see what you think about this. Thanks!
En respuesta a Jin Hong

Re: Python3 GUI (tk) questions

por Richard Lobb -
Sure. The python3_tkinter question type you're using is a fairly old one. At that time, the 1-week GUI section of the course required students to use textvariables, as that was deemed to be the "correct" approach by some of our teaching team. In a later version of the course I switched to using the get method on widgets instead, and didn't teach textvariables at all. Of course, the question type was adapted accordingly. As I recall, though, some widgets didn't have a get method, so couldn't be used at all in that version of the course!
 
tkinter has some pretty horrible behaviours so no matter what you do there will be times when students submit code that works with the actual tkinter and fails with the simulated version in the question type. All you can do is try to provide helpful error messages and use low or no penalties.
 
Happily I no longer teach a course that uses tkinter :-)