Computer Science Canada Creating buttons to store inputted data. |
Author: | bwong [ Mon Apr 25, 2011 3:36 pm ] | ||
Post subject: | Creating buttons to store inputted data. | ||
What is it you are trying to achieve? Write a program that draw a shape with properties specified by the user. The program should provide a graphical user interface for user to select a shape, and a colour. For bonus mark, your program should let the user select the size as well. Users must select the properties by clicking the corresponding buttons in the right order. If the order is not correct, the program should output error messages and no shapes will be drawn. What is the problem you are having? I was able to format everything, and create the buttons. But, I am having an issue with storing their choices of shape and color in order to create a final product. Describe what you have tried to solve this problem I have searched online.... to no avail. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using Turing 4.1.1 |
Author: | Tony [ Mon Apr 25, 2011 3:46 pm ] |
Post subject: | RE:Creating buttons to store inputted data. |
you could store various information in variables. |
Author: | bwong [ Mon Apr 25, 2011 3:55 pm ] | ||
Post subject: | Re: Creating buttons to store inputted data. | ||
Yessir, I understand that. I know the text based version, like:
But how would I do that for my situation right now? so that, if the user pressed "Square" and "Red", the final product would be a red square? |
Author: | Tony [ Mon Apr 25, 2011 4:15 pm ] | ||
Post subject: | RE:Creating buttons to store inputted data. | ||
you can also assign values yourself
At what point in the code do you know that a user has pressed a particular button? |
Author: | bwong [ Mon Apr 25, 2011 4:19 pm ] |
Post subject: | Re: Creating buttons to store inputted data. |
Tony wrote: At what point in the code do you know that a user has pressed a particular button? I don't know. I'm not very versed in Turing, but this will be a significant part of my mark, so I have been working all day on this |
Author: | Tony [ Mon Apr 25, 2011 6:07 pm ] |
Post subject: | RE:Creating buttons to store inputted data. |
Read the documentation for GUI.CreateButton; You seem to have the code that does all the right things, but perhaps it's just not yet fully understood. |
Author: | bwong [ Mon Apr 25, 2011 8:06 pm ] | ||||
Post subject: | Re: RE:Creating buttons to store inputted data. | ||||
Tony @ Mon Apr 25, 2011 6:07 pm wrote: Read the documentation for GUI.CreateButton; You seem to have the code that does all the right things, but perhaps it's just not yet fully understood.
Alright, I read the entire document twice, throughly, but, it doesn't exactly help me. I believe it would be correct to reword my plead for assistance: I would like to create a program which creates user-defined shapes. The user will be able to chose (1) a shape, (2) a colour, and (3) the size. My approach to this issue is by creating a menu-like GUI. I have used some buttons, as you would see if you were to copy and paste the code (below) into turing. I was able to get all the buttons to appear, but was unable to use the buttons to create a final image. I would like it to be kind of like this (below), except in a visual form, where the user can click on a box, or button instead of typing in a letter:
Here is an updated code... Nothing special, just with all the wanted buttons there
|
Author: | Tony [ Mon Apr 25, 2011 9:09 pm ] | ||
Post subject: | RE:Creating buttons to store inputted data. | ||
Alright, lets walk through this. The documentation starts out with Quote: The button widget is used to implement a textual button. When you click on a button, the button's action procedure is called. You sort of understand that well enough to link to SquarePressed in
and to actually implement that procedure. So: - button linked to a procedure - button pressed -> procedure runs - that procedure has no other entry points - when the procedure runs, we could assume that the corresponding button has been pressed Now you just need to "remember" (meaning record information somewhere, typically variables), that you were in that state. |
Author: | bwong [ Tue Apr 26, 2011 12:11 pm ] | ||
Post subject: | Re: RE:Creating buttons to store inputted data. | ||
Tony @ Mon Apr 25, 2011 9:09 pm wrote: Alright, lets walk through this. The documentation starts out with
So: - button linked to a procedure - button pressed -> procedure runs - that procedure has no other entry points - when the procedure runs, we could assume that the corresponding button has been pressed Now you just need to "remember" (meaning record information somewhere, typically variables), that you were in that state. But how would I do that last part? EDIT: I felt the need to use a less advanced code, since I am not so versed in Turing. Hence I have this now:
|
Author: | Tony [ Wed Apr 27, 2011 2:33 am ] | ||
Post subject: | RE:Creating buttons to store inputted data. | ||
Here's a trivial example that should give you an idea
|