[Tutor] What is this code doing? What is it?

2019-05-12 Thread Matthew Polack
We're beginners  trying to learn Python and have this sample code:

https://github.com/PySimpleGUI/PySimpleGUI/blob/master/ProgrammingClassExamples/Win10%20versions/2a.%20PSG%20(checkbox%20and%20radiobuttons)%20-%20Copy.py


There is a section of code that has this line::

result = str(' Cost: ' + '${:.2f}'.format(cost))

But I don't understamd what the curly brace part is actually doing:
{:}

'${:.2f}'

I think the 2f means to use 2 decimal places...but what does the rest of
this do?

..curly braces apparenly are for dictionaries...but I don't get how this is
a dictionary..or what this {:} command is actually doing?

Thanks for any clues or links to an easy to understand tutorial or
something on this feature.

- Matt

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] What does 'Bind Return Key' do?

2019-04-29 Thread Matthew Polack
Hi,

We're learning Python with PySimpleGUi and have used this example program...

https://github.com/PySimpleGUI/PySimpleGUI/blob/master/ProgrammingClassExamples/Win10%20versions/1d%20PSG%20(named%20input%20keys%20and%20catch%20errors).py


There is a mystery command that says:

[sg.ReadButton('Submit', bind_return_key = False)]]

If I change this 'Bind_Return_Key' value from False to True...or in fact
delete it entirely, it appears to make do difference whatsoever to the
functioning of the program that I can see...

Could someone explain what the purpose of this could be? I'm guessing it
has to have a reason to be there!

Thanks!

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Recommended Resurce or strategy for beginning students

2019-02-21 Thread Matthew Polack
Hi All,

Just wanted to update this thread regarding a resource for beginning
students. We are now 4 weeks into the course and have found an excellent
youtube series that goes from absolute basics.
https://www.youtube.com/playlist?list=PLLAZ4kZ9dFpMMs5lskzBApYXn0bl7emsW

The big advantage for us in a classroom context is that students can work
through this at their own pace using an Ipad to watch videos and then a
computer to code..

I have some students who are flying through the course and are ready for
more advanced topics..others are working more slowly...but all of them are
enthusiastic and engaged...and the beauty of using a series like this is
they can just go onto the harder topics when they are ready.

After we finish this series my plan is then to go onto Mike's excellent
PySimpleGUI resource...https://pysimplegui.readthedocs.io/tutorial/

I'm sure the students will then enjoy the GUI elements of the code.

We'll also use the Turtle import option to add some graphics interactions

We then might look to use a robotics  resource which is GoPiGo
https://www.dexterindustries.com/gopigo-in-python-tutorials/ which gives us
a chance to explore robotics with Python.

The pleasing thing is how keen the students are to keep learning and asking
questions

Thanks again for all your support and ideas!

Matthew Polack

On Tue, Feb 5, 2019 at 3:05 PM David  wrote:

> On Tue, 22 Jan 2019 at 20:30, Matthew Polack
>  wrote:
> >
> > Hi All,
> >
> > In our growing school we're teaching Python programming for the first
> time
> > as an elective subject with Year 9 and 10 students. (Had a dabble at this
> > last year with 3 students in Year 11)
>
> Hi Matthew and other readers,
>
> I wonder if you and any others here involved in classroom/group teaching
> might be interested in this recent presentation that I stumbled across:
>
> https://media.ccc.de/v/35c3-9800-how_to_teach_programming_to_your_loved_ones
>
> The section of this video which motivates me to write here is the two
> minutes
> from 19:00 to 21:00.
>
> What I find most interesting is his motivation mentioned there: he claims
> his
> procedure solves the problem of any students becoming "lost", feeling
> "stuck"
> at any particular step, not knowing what to do next, and unable to proceed
> without guidance.
>
> Quoting from the synopsis:
> The talk is based on many years of research by the Program by Design,
> DeinProgramm, and Bootstrap educational projects, as well as over 30 years
> of personal teaching experience in school, university and industrial
> contexts.
> A word of warning: The resulting approach is radically different from most
> teaching approaches used in universities and schools. In particular, it
> avoids
> teaching purely through examples and expecting students to develop the
> skills to arrive at the solutions on their own. Instead, it teaches
> explicit
> methodology that enables students to solve problems of surprising
> complexity
> on their own, whether they are 11 or 55, whether in a classroom, a training
> facility, or your home. Extensive documentation, material, and software to
> support this methodology is available for free.
>
> For anyone considering watching the whole presentation, I expect that there
> are many other aspects of this presentation to which people here could
> react
> negatively, for example:
>
> 1) The given title is misleading, in my opinion its subtitle would be much
> more
> representative: "Enabling students [by] example-driven teaching".
>
> 2) It recommends against Python, about this I have no opinion (except
> to respect the presenter's experience) and that is not why I am posting it
> here.
>
> 3) It emphasises functional programming style.
>
> 4) Despite possibly having an audience including skilled programmers, in
> the
> second half of the presentation the presenter does not skip quickly over
> the
> concept, but instead he chooses to demonstrate his concept by reproducing
> the same deliberate steps that he would use in a classroom of students
> with low ability.
>
> Despite all these possibly alienating aspects, and possibly others, I'm not
> really interested in those aspects, because they're not useful to me and so
> I choose to ignore them, instead focussing on what might be useful.
>
> Years ago I spent about a decade teaching undergraduate engineering
> students, from that context I consider this interesting and relevant.
> This presenter mentions that he has 30 years of of experience
> and commitment to teaching this subject, and considers most of his
> efforts a "failure" (at 02:00). Learning from such a person can save other
> practitioners a great deal of effort.
>
> So I felt that this was 

Re: [Tutor] Recommended Resurce or strategy for beginning students

2019-02-06 Thread Matthew Polack
Thanks Alan, David and Mike,

Really appreciate those thoughts and ideas suggested.. I will check out the
full video David...but the part I've looked at has some great food for
thought..is extremely relevant.This quote from the description is very true:

"showing them how to copy-paste a few example programs and change a few
parameters is easy, but bridging from there to building substantial
programs is a different game entirely. This talk is about how to teach
programming successfully, through comprehensible *design recipes*, which
anyone can follow "

Is interesting also his reference to robotsthat we could spend a year
using robots...but not really getting deep learning happening...which is
what I was wondering too...

I think initially I do have to start with some example programsand if
nothing else try and get them inspired to go further
Anyway thanks...is going to be quite an interesting journey of learning for
both students and teacher this Semester!

Will keep looking through the suggestions and resources mentioned.

Thank you,

Matthew



On Tue, Feb 5, 2019 at 4:02 PM David  wrote:

> On Tue, 5 Feb 2019 at 15:03, David  wrote:
> >
> > 1) The given title is misleading, in my opinion its subtitle would be
> much more
> > representative: "Enabling students [by] example-driven teaching".
>
> Hi again,
>
> Sorry for replying to myself, but I want to correct something wrong that
> I wrote above. The actual subtitle of the presentation is
> "Enabling students over example-driven teaching"
> and I think the intendend meaning of that is
> "Enabling students [is better than] example-driven teaching".
>
> Also I forgot to mention that part of my motivation for writing is some
> things Alan wrote:
>
> On Tue, 22 Jan 2019 at 20:59, Alan Gauld via Tutor 
> wrote:
> >
> > In the UK many schools use the RaspberryPi project to teach robots to
> > kids as part of their Technology courses. The programming is picked up
> > by osmosis on an as-needed basis. The upside is that it's a lot of fun
> > and gets kids used to the concepts of hardware and software working in
> > unison. The downside is that they learn a lot of bad coding habits and
> > don't understand the theoretical underpinnings of either the hardware or
> > software. But as a way to get them hooked it works well .
>
> On Mon, 4 Feb 2019 at 21:07, Alan Gauld via Tutor 
> wrote:
> >
> > I'm not a professional or trained teacher but over
> > the last 30 years or so I've been involved in classes
> > teaching everything from 11 years to 70+ years old
> > students. I've always, without fail, found that some
> > students (say 10-20% of a class) just don't get
> > programming. It seems to me that some folks just
> > don't have their brains wired the right way. It
> > doesn't matter what tools or languages you use, it
> > even happens with graphical tools like flow charts.
> > Some people just don't understand the concepts of
> > logical flow and problem decomposition.
> >
> > You can, of course, force feed these folks to some
> > extent and they will pick up the basics with a
> > struggle but they will never be able to create
> > any significant body of code on their own. I'm
> > sure psychologists etc will have an explanation
> > for this but I've given up trying to explain it,
> > I now just accept that some people don't think
> > that way.
>
> I believe the video presentation addresses exactly these points.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Recommended Resurce or strategy for beginning students

2019-02-04 Thread Matthew Polack
Hi All,

Firstly thanks so much for all the suggestions a while back re: recommended
method for Python...really appreciate the ideas.

We had our first lesson today (With 15 year olds) where I started with the
basic command line..and did a simple "Hello World" type program...just to
show how something could be run straight from notepad and command line...

We then went to IDLE and made a simple 'Maths Calculator'

All of this went quite well...but as the long session started to wind down
(Is a double lesson on a Monday)...I did start to notice the following:

1.) One group of students (probably most)..actively problem solving..trying
things...googling all sorts of ways of improving their code...figuring out
new ways of doing things...will go a long way.
2.) Another smaller group started to hit the wall...and were struggling for
internal drive...needed to be 'hand fed'

Is going to be interesting going forward how to both cater for the
'indpendent workers' whilst still keeping the 'unenthused unless
entertained' group engaged! The joys of teaching...but will certainly try
some of the suggestions mentioned...PySimpleGUI..Turtle graphics
etcthey will be very helpful. Thanks.


Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au


On Wed, Jan 23, 2019 at 1:21 PM Sean Murphy  wrote:

> I like this concept. The only additional information I would add in
> relation to any training or educational information. You must include
> accessibility. As the laws in many countries require this to be a part of
> the product. So it is a perfect time to educate students on this important
> topic. A high level awareness is required only.
> Introducing the basics. Keyboard navigation, colour contrast, ensuring the
> GUI works with a screen reader. The platforms used for GUI should do most
> of the heavy lifting.
>
> The other aspect is you need to ensure the course is accessible to
> possible disable students for now and the future. If you are based in the
> Usa. Then there could be legal requirements for this. Not sure. Out of my
> scope of focus in the accessibility world.
>
>
> A bare minimum is to understand the bare basics which are called POUR.
> Reference W3C for the explaination.
>
> Sean
>
> My experience is the part
>
> > On 23 Jan 2019, at 1:17 am, Mike Barnett 
> wrote:
> >
> > I like the idea of starting out right away on a GUI.  I know this is
> completely backwards to what would normally be taught, but hear me out.
> Kids today are used to GUI interfaces.  They're on their phones, their
> computers, their TV  sets.
> >
> > Why not teach kids to output to a window instead of a command line?
> What if it's just was easy, or easier, to work with a GUI as it is the
> command line?
> >
> > To output to the command line in standard Python:
> > print('my string', variable1, variable2)
> >
> > To output the same information to a window using PySimpleGUI:
> > Popup('my string', variable1, variable2)
> >
> > Or, you can "print" to a debug window if that's your thing.
> > Print('takes the same parameters as print')
> >
> > If the ultimate goal is to teach kids about how to design a GUI window,
> how to lay out a GUI using good user interface design principals, then it
> would be nice to get the GUI coding out of the way and let the focus
> instead be on the GUI itself.  This is when having a drag-and-drop Designer
> Tool is handy.  If not, then the next best thing is a simple programming
> interface.
> >
> > PySimpleGUI was designed so that the code visually matches the window
> layout.
> >
> > It's capable of duplicating pretty much any layout and widget
> combination that you can create coding directly to tkinter's (or Qt's or
> WxPython's) interfaces.  PySimpleGUI simply creates and executes the
> "boilerplate" code that is often brought up when GUIs are discussed.
> >
> > A goal was to remove all of the boilerplate code and provide a
> programmer with a simple, friendly and flexible set of APIs.  You write a
> single line of code per row of widgets in your window plus a 1/2 dozen
> lines to implement the event loop.
> >
> > I don't see the harm in approaching the problem from a different
> direction.  It could be wildly successful.  Or... not...  The worst that
> can happen is you screw up a classroom full of future programmers, creating
> a warped vision that GUIs can be fun and easy.
> >
> >
> > @mike
> >
> > -Original Message-
> > From: Matthew Polack 
> > Sent: Tuesday, January 22, 2019 1:58 AM
> > To: t

[Tutor] Recommended Resurce or strategy for beginning students

2019-01-22 Thread Matthew Polack
Hi All,

In our growing school we're teaching Python programming for the first time
as an elective subject with Year 9 and 10 students. (Had a dabble at this
last year with 3 students in Year 11)

I'm wondering what specific resource or stategy people would recommend for
absolute beginners?

ie. a course or program, book,...set of activities to follow that
strategically introduces and develops key skills.

At this age level I don't think we need to be achieving 'rocket
science'..but rather giving the students a good solid introduction.

Some of the leadership wanted me to use this programming in combination
with building robots...I've even wondered whether this is trying to achieve
too many things...and we're better off focused on programming itself... but
am open to this idea too...

I've had a play with using the excellent PySimpleGUI...which is an
excellent resource for building a GUI...but I've realised before doing too
much of this we might need to get a grip on core fundamentals

The challenge is trying to find a way to making this 'fun' for students
whilst also having them genuinely learn rather than just 'copying pasting'
code...achieving something that looks good...but not really understanding
what they are doing.

So far my strategy will be:

1.) Establish some core basics(utlising some form of 'course',,,which goes
through basics of syntax..variables...loops etc. utilising just raw
code...(probably a simple 'Adventure Game')
2.) Build some simple programs using PySimple GUi..eg. Some quiz games etc.
(there are some great examples on Github by another teacher and also the
author Mike of PySimpleGUI.
3.) Possibly explore robotics.

Can anyone make any recommendations on either resources or
teaching/learning strategy/curriculum.

Thank you,
Matt


Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Any 'graphical' ways of learning Python

2018-12-11 Thread Matthew Polack
Hi Mike and everyone who replied to the tutor question re: GUI ideas for
Python.

Really value all the ideas and suggestions...that is very helpful! Thanks
for taking time to reply with so much great information.

We're just in wind down mode/rush for our close of school year ...but will
really enjoy looking through all the various links and ideas as I prepare
the coding course for 2019. Will use them, to upskill myself too.

Thanks so much!

- Matthew Polack



On Fri, Dec 7, 2018 at 6:05 AM Mike Barnett 
wrote:

> Oh, one more thing on this topic... there are tutorial videos available
> for PySimpleGUI, both basic and advanced.
>
> Basic 5 video series:
> https://www.youtube.com/playlist?list=PLl8dD0doyrvHMoJGTdMtgLuHymaqJVjzt
>
> Additional 9 in-depth videos:
> https://www.youtube.com/playlist?list=PLl8dD0doyrvHMoJGTdMtgLuHymaqJVjzt
>
>
> -mike
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Any 'graphical' ways of learning Python

2018-12-05 Thread Matthew Polack
Hi All,

We're using Python with our Year 9 and 10 students to teach programming.
I've started with basic console programming...doing simple games like a
quiz game etc.

Students always seem to like 'graphics'..one of the reasons things like
'Scratch' are so popular in schools is because of  the ready made GUI.

My concern with things like 'Scratch' and 'Game Engines' is that perhaps
kids can miss out on  learning core fundamentals...but can appreciate some
visuals can be very motivating...

Can anyone recommend any ways of integrating 'graphics' but in a simpler
way.

I've had some experience with TKinter...(which is still quite a jump for
beginners)also can see that 'Pygame' might offer some of this...

also have seen some tutorials on Udemy that encourages using the 'Turtle'.

Does anything else come to find for helping kids stay engaged when they
start to get tired of just text based console programming?

Thanks for any suggestions.


Matthew Polack | Teacher

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] A Python program to Summarise weather results?

2018-08-30 Thread Matthew Polack
Hi,

We have a spreadsheet from a local weather station.it summarises the
amount of rainfall per day since 1863.

http://www.bom.gov.au/jsp/ncc/cdio/weatherData/av?p_nccObsCode=136_display_type=dailyDataFile_startYear=1863_c=-1249186659_stn_num=079028

We'd love to be able to summarise this into years eg. Total rainfall of
1863, 1864 all the way through to 2018.

Would Python be able to do this using the csv file?

Thanks,

Matt




Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Times Tables Program that constantly tells you that you are wrong!

2018-08-24 Thread Matthew Polack
Thanks Alan and Peter for all your help with this.

I got it all to work..thank you..

like learning a musical instrument...probably just need some time
consolidating the current skill set...has been a lot to take in...

but getting there steadily...and bit by bit it is starting to make sense..

I'll probably stick with the traditional  %. method too for a while because
that is now what I understand.

thanks...will keep trying things..and then also reading through the various
docs provided...+ your emails.

Thank you.






Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au

On Thu, Aug 23, 2018 at 10:34 PM, Alan Gauld via Tutor 
wrote:

> On 23/08/18 06:10, Matthew Polack wrote:
>
> > I'm also trying to solve the rounding issue...but can't work out the
> syntax
> > using the example provided...have tried this but I get an error...
> >
>
> > def viewPercent():
> >  percentCalc = score/total*100
> >  percentViewLab["text %.2f"] % percentCalc
>
> OK, the problem here is mixing up your data with TKinter's
> (inherited from Tcl/Tk) mechanism for accessing widget
> attributes.
>
> percentViewLab["text %.2f"]
>
> This tells Tkinter to fetch an attribute of your widget
> called "text %.2f". Of course there is no such attribute,
> it is called just "text".
>
> percentViewLab["text %.2f"] % percentCalc
>
> This tries to insert the percentCalc value into the
> string returned by the widget.
>
> Again that's not what you want. You want to insert
> the data into a string which will then be assigned
> to the widget's text attribute.
>
> val = "%.2f" % percentCalc  # eg. -> val = "0.76"
>
> Now insert val into your widget
>
> percentViewLab["text"] = val
>
> or equivalently:
>
> percentViewLab.config("text", val)
>
> You can of course combine all of that with
>
> percentViewLab["text"] = ".2f" % percentCalc
>
> Personally I tend to separate the creation of the
> string from the widget assignment because it makes
> it easier to debug by printing the string to the
> console.
>
> One final note. When using % to inject data into
> a format string you MUST put the percent immediately
> after the format string. No commas or parentheses
> allowed.
>
> The % formatting style is preferred by old school
> programmers (like me) who came from the world of C and
> its relatives because C uses a very similar style in
> its printf() family of functions. However, new programmers
> may find the format() method of a string more obvious.
> (I'm thinking about your students here)
>
> Using format your case would look like:
>
> val = "{:.2f}".format(percentCalc)
>
> And the previous example would be:
>
> fail_str = """
> Sorry, you got it wrong,
> the correct answer was {:d}
> Your current score is: {:f}""".format(answer,score)
>
> It is quite similar except the placemarkers are {}
> and you call the format() method. The formatting
> characters inside the {} are different too - you
> need to read the docs... There are zillions of examples.
> You might find it more logical.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Times Tables Program that constantly tells you that you are wrong!

2018-08-23 Thread Matthew Polack
Hi Alan,

I'm also trying to solve the rounding issue...but can't work out the syntax
using the example provided...have tried this but I get an error...

_tkinter.TclError: unknown option "-text %.2f"

.I'm sure it is a simple syntax issue...but I don't know what it is.

def viewPercent():
 percentCalc = score/total*100
 percentViewLab["text %.2f"] % percentCalc



 '''
 # This was my working version pre the version suggest above.
 percentCalc = score/total*100
 rounded = round(percentCalc, 2)
 percentViewLab["text"] = rounded
 '''


'''

Instructions given:

>>> s = "Here is a string with a rounded float: %.2f" % 42.3456789
>>> s
'Here is a string with a rounded float: 42.35'
'''
Thanks for any clues.

- Matt



Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au

On Fri, Aug 17, 2018 at 8:18 PM, Alan Gauld via Tutor 
wrote:

> On 17/08/18 03:19, Matthew Polack wrote:
>
> > def viewPercent():
> > percentCalc = score/total*100
> > rounded = round(percentCalc, 2)
> > percentViewLab["text"] = rounded
>
> Since you only want the rounded value for display
> this is usually achieved using string formatting:
>
> >>> s = "Here is a string with a rounded float: %.2f" % 42.3456789
> >>> s
> 'Here is a string with a rounded float: 42.35'
>
> That doesn't change the value of the variable but changes how
> it is displayed. There are lots of other options in format
> strings to control justification, padding etc. You should
> definitely explore their capabilities. Just because you
> are using a GUI rather than a console doesn't mean the
> string methods are any less useful.
>
> > from tkinter import *
> > import random
> >
> > # GLOBAL VARIABLES
> > # Created with a starting value.
> > answer = 0
> > score = 0
> > wrong = 0
> > mistakes = 0
> > total = 0
> >
> > def makeproblem():
> > global answer
> >
> > txt.delete(0.0, 'end')
> > sentence = "Here is your problem "
> > number1 = random.randint(2,12)
> > number2 = random.randint(2,12)
> > answer = number1 * number2
> >
> > center = txt.tag_config("center", justify="center")
> >
> > txt.insert(0.0, sentence, "center")
> > txt.insert(2.2, number1, "center")
> > txt.insert(3.3, " x ", "center")
> > txt.insert(4.4, number2, "center")
>
> All of the above could be replaced with a single format string
> and a single insert.
>
> display = """
> Here is your problem:
>
> %d x %d
> """ % (number1, number2)
>
> txt.insert(1.0,display, "center")
>
> > def checkanswer():
> > txt.delete(0.0, 'end')
> >
> > global score
> > global mistakes
> > global total
>
> Its conventional (although not necessary) to put all
> globals at the very top of the function.
>
> > response = int(answerbox.get())
> > wordScore = "Your score is now "
> > if response == answer:
> > score += 1
> > total += 1
> > result = "Great Job! "
> > root.update()
> > viewSC()
> > viewPercent()
> > viewTotal()
> > else :
> > total += 1
> > result = "Sorry...you made a mistake. \n "
> > # the \n above adds a line break.
> > mistakes += 1
> > viewMistakes()
> > viewTotal()
> > viewPercent()
>
> Notice you display Total and Percent in both block
> but do it in an inconsistent order.
> If you took both of this display calls outside
> the if/else you only need to call them once and
> they will be in the same sequence for all cases.
>
> > center = txt.tag_config("center", justify="center")
> > txt.insert(0.0, result, "center")
> > txt.insert(3.0, wordScore, "center")
> > txt.insert(8.1, score, "center")
> ># txt.insert(1,1, "Score is")
> > #txt.insert(3,3, score)
>
> Again this could all be replaced with string
> formatting and a single insert()
>
> > def about():
> > txt.delete(0.0, 'end')
> >
> > instructions = "Here is how you play the game. Press generate
> > problem..and then enter your ans

Re: [Tutor] Times Tables Program that constantly tells you that you are wrong!

2018-08-23 Thread Matthew Polack
ot;)


photo = PhotoImage(file="pool.gif")

label = Label(image=photo)
label.image = photo # keep a reference!
label.grid(row=0, columnspan=20)

# MENU SECTION
# These are included as an example menu structure...in many cases they
don't do much...but do feature instructions and a quit feature.

# create a toplevel menu
menubar = Menu(root)

# Just an example of printing  hello to console for use in a menu item.
def hello():
print ("hello!")

# display the menu
root.config(menu=menubar)

# create a pulldown menu, and adds it to the menu bar
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command=makeproblem)
filemenu.add_command(label="Save", command=makeproblem)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)

menubar.add_cascade(label="File", menu=filemenu)

# create more pulldown menus
editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="Cut", command=checkanswer)
editmenu.add_command(label="Copy", command=checkanswer)
editmenu.add_command(label="Paste", command=checkanswer)
menubar.add_cascade(label="Edit", menu=editmenu)

helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="About", command=about)
menubar.add_command(label="Hello", command=hello)
menubar.add_cascade(label="Help", menu=helpmenu)
menubar.add_command(label="Quit", command=root.quit)


# Plain text labels at top of window.
timeslabel = Label(root, text="Times Tables Practice", fg="white",
bg="blue", font=("arial", 36, "bold"))
timeslabel.grid(columnspan=12, sticky='ew')
instruction = Label(root, text="Please click on the button to generate a
problem", fg="blue", bg="white", font=("arial", 16, "bold"))
instruction.grid(row=2, columnspan=20)

# Makes an entry box with the variable of 'answerbox'
answerbox = Entry(root, bg="grey", font=("arial", 24, "bold"), justify
="center")
answerbox.grid(row=15, columnspan=2, padx=0, pady=0, sticky=EW)

# Makes a button that generate the Times Tables problem
btn = Button(root, text="GENERATE PROBLEM", bg="blue", fg="white",
command=makeproblem)
btn.grid(row=11, columnspan=2, sticky=EW)

# Makes a button that checks the answer
btn = Button(root, text="CHECK ANSWER", bg="darkblue", fg="white",
command=checkanswer)
btn.grid(row=13, columnspan=2, sticky=EW)

#TEXT BOX AREA
#This important command creates the text box called 'txt'. This is used for
all the text output.
txt = Text(root, width=35, height=3, wrap=WORD, font=("arial", 20, "bold"))
txt.grid(row=12, columnspan=2, sticky=EW )


#Adds a blankline below answer box...but leaves top alignment alone. You
could use PAD...but that command does both sides. There may be another way
to achieve this.
blankline3 = Label(root, text = "", bg = "white")
blankline3.grid(row=17, columnspan=2, sticky='ew')

# SCORING LABELS AND RESULTS SECTION
# Places the labels and the results beside each other in column 0 and
column 1.
# Note: Each 'View' label grabs the starting score from the declarations at
the top. eg. score = 0
scorelab = Label(root, text="Score", bg="green", fg="white", font=("arial",
20, "bold"))
scorelab.grid(row=18, column=0, sticky=E)

scoreViewLab = Label(root, text=score, fg="black", bg="grey",
font=("arial", 20, "bold"))
scoreViewLab.grid(row=18, column=1, sticky=W)

totalLab = Label(root, text="Out of", bg="purple", fg="white",
font=("arial", 20, "bold"))
totalLab.grid(row=19, column=0, sticky=E)

totalViewLab = Label(root, text=total, fg="black", bg="grey",
font=("arial", 20, "bold"))
totalViewLab.grid(row=19, column=1, sticky=W)

mistakeslab = Label(root, text="Mistakes", bg="red", fg="white",
font=("arial", 20, "bold"))
mistakeslab.grid(row=20, column=0, sticky=E)

mistakesViewLab = Label(root, text=mistakes, fg="black", bg="grey",
font=("arial", 20, "bold"))
mistakesViewLab.grid(row=20, column=1, sticky=W)

percentlab = Label(root, text="Percentage", bg="aqua", fg="white",
font=("arial", 20, "bold"))
percentlab.grid(row=21, column=0, sticky=E)


percentViewLab = Label(root, text=0, fg="black", bg="grey", font=("arial",
20, "bold"))
percentViewLab.grid(row=21, column=1, sticky=W)


#SCORE UPDATE SECTION.
# Each of these functions allows the 4 scoring labels to be updated as
answers are deemed correct or incorrect with the if/else statement.
# The viewPe

[Tutor] Recommended way for end users to run our Python programs?

2018-08-17 Thread Matthew Polack
Hi,

We're enjoying learning Python in our school...but I have a question
regarding the way the end users should ideally run the software.

Does this always require Python being installed as a full language on the
end users computer?

ie. At the moment we install Python...add it to the path in
Windows...develop and run the software we make...workable for the
developer.but a bit of mucking around for someone who goes to use our
programs.

Is  there some other way to get it working in either a browser...or as a
'self contained' windows app ...or an Android/IOS appor a regular
Windows .exe file to install?

Just trying to get my head around the 'end game' of all this?

Thanks,

Matt





If we make a python.py program and want people on Windows to run it...does
this mean there must be Python installed on that computer in order to run
it.

Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Times Tables Program that constantly tells you that you are wrong!

2018-08-17 Thread Matthew Polack
y be another way
to achieve this.
blankline3 = Label(root, text = "", bg = "white")
blankline3.grid(row=17, sticky='ew')

# SCORING LABELS AND RESULTS SECTION
# Places the labels and the results beside each other in column 0 and
column 1.
# Note: Each 'View' label grabs the starting score from the declarations at
the top. eg. score = 0
scorelab = Label(root, text="Score", bg="green", fg="white", font=("arial",
20, "bold"))
scorelab.grid(row=18, column=0, sticky=E)

scoreViewLab = Label(root, text=score, fg="black", bg="grey",
font=("arial", 20, "bold"))
scoreViewLab.grid(row=18, column=1, sticky=W)

totalLab = Label(root, text="Out of", bg="purple", fg="white",
font=("arial", 20, "bold"))
totalLab.grid(row=19, column=0, sticky=E)

totalViewLab = Label(root, text=total, fg="black", bg="grey",
font=("arial", 20, "bold"))
totalViewLab.grid(row=19, column=1, sticky=W)

mistakeslab = Label(root, text="Mistakes", bg="red", fg="white",
font=("arial", 20, "bold"))
mistakeslab.grid(row=20, column=0, sticky=E)

mistakesViewLab = Label(root, text=mistakes, fg="black", bg="grey",
font=("arial", 20, "bold"))
mistakesViewLab.grid(row=20, column=1, sticky=W)

percentlab = Label(root, text="Percentage", bg="aqua", fg="white",
font=("arial", 20, "bold"))
percentlab.grid(row=21, column=0, sticky=E)


percentViewLab = Label(root, text=0, fg="black", bg="grey", font=("arial",
20, "bold"))
percentViewLab.grid(row=21, column=1, sticky=W)


#SCORE UPDATE SECTION.
# Each of these functions allows the 4 scoring labels to be updated as
answers are deemed correct or incorrect with the if/else statement.
# The viewPercent function includes the calculation to update the
percentView label...shows an example of a calculation within a label.

def viewSC():
scoreViewLab["text"] = score

def viewTotal():
totalViewLab["text"] = total

def viewMistakes():
mistakesViewLab["text"] = mistakes

def viewPercent():
percentViewLab["text"] = score/total*100

# This keeps the program running.
root.mainloop()



Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au

On Thu, Aug 16, 2018 at 7:11 PM, Alan Gauld via Tutor 
wrote:

> On 16/08/18 08:18, Matthew Polack wrote:
>
> > The last remaining issue is the program does not calculate the percentage
> > right when you make mistakes...it just keeps giving a result of 100%.
>
> > def percentCheck():
> > global percentScore
> > global score
> > global mistakes
> > global total
>
> While you do need some globals in your program you only
> need to declare the ones you are changing. In this case
> you only need to declare percentScore as global.
>
> > percentScore = float(score/total) * 100
>
> To debug this I would add a print line such as
>
> print(score, total)
>
> Since if you always get 100 it suggests that score
> and total are the same.
>
> One problem here is that you are converting to float
> after doing the division. That's usually the wrong
> thing to do. In fact I notice you do that a lot of
> conversions on expressions. Its much safer to do the
> conversions on the individual values then perform
> the computation after the conversion.
>
> In fact in this case (and most of the other similar
> cases) you should not need the float conversion since
> you already converted the values when you read them
> from the GUI. You should aim to convert the data
> into the correct type as soon as possible then you
> will not need to use conversions anywhere else.
>
> Some more observations below...
>
> > viewPercent()
> >
> >
> > def makeproblem():
> > # deletes anything in text box from location 00 to the end
> > global answer # access global answer
> >
> > txt.delete(0.0, 'end')
> >
> > sentence = "Here is your problem "
> >
> > number1 = random.randint(2,12)
> > number2 = random.randint(2,12)
> >
> > answer = number1 * number2
> >
> > txt.insert(0.0, sentence)
> > txt.insert(2.2, number1)
> > txt.insert(3.3, " x ")
> > txt.insert(4.4, number2)
> >
> > def checkanswer():
> > # deletes anything in text box from location 00 to the end
> > txt.delete(0.0, 'end')
> &g

Re: [Tutor] Times Tables Program that constantly tells you that you are wrong!

2018-08-16 Thread Matthew Polack
Hi All,

Thanks to your help I've nearly got my demo 'Times Tables' program fully
working.

The last remaining issue is the program does not calculate the percentage
right when you make mistakes...it just keeps giving a result of 100%.

I've looked and head scratched...and am not sure.

Can anyone figure out what is wrong with this code?

Thanks!

- Matt

from tkinter import *

import random

answer = 0
score = 0
wrong = 0
mistakes = 0
percentScore = 0
total = 0

def percentCheck():
global percentScore
global score
global mistakes
global total

percentScore = float(score/total) * 100
viewPercent()


def makeproblem():
# deletes anything in text box from location 00 to the end
global answer # access global answer

txt.delete(0.0, 'end')

sentence = "Here is your problem "

number1 = random.randint(2,12)
number2 = random.randint(2,12)

answer = number1 * number2

txt.insert(0.0, sentence)
txt.insert(2.2, number1)
txt.insert(3.3, " x ")
txt.insert(4.4, number2)

def checkanswer():
# deletes anything in text box from location 00 to the end
txt.delete(0.0, 'end')

global answer
global score
global wrong
global mistakes
global percentScore
global total

# checks for what is written in answerbox
response = int(answerbox.get())
wordScore = "Your score is now "

if response == answer:
score = int(score + 1)
total = int(total + 1)
result = "Great Job! "
root.update()
viewSC()
percentCheck()
viewPercent()
viewTotal()


else :
score= int(score + 1)
total = int(total + 1)
result = "Sorry...you were wrong"
mistakes = int(mistakes + 1)
viewWrong()
viewTotal()
percentCheck()
viewPercent()

txt.insert(0.0, result)
txt.insert(3.0, wordScore)
txt.insert(8.1, score)
   # txt.insert(1,1, "Score is")
#txt.insert(3,3, score)


root = Tk()
root.geometry("640x700+0+0")
root.title("Times Tables")


timeslabel = Label(root, text="Times Tables Practice", fg="white",
bg="blue", font=("arial", 36, "bold"))
timeslabel.grid(columnspan=12, sticky='ew')
instruction = Label(root, text="Please click on the button to generate a
problem", fg="blue", bg="white", font=("arial", 16, "bold"))
instruction.grid(row=2, columnspan=20)

blankline = Label(root, text = "", bg = "white")
blankline.grid(row=12, sticky='ew')

# Makes an entry box with the variable of 'answerbox'
answerbox = Entry(root, bg="aqua", font=("arial", 24, "bold"))
answerbox.grid(row=15, columnspan=2, sticky=EW)

# Makes a button that generate the Times Tables problem
btn = Button(root, text="GENERATE PROBLEM", bg="blue", fg="white",
command=makeproblem)
btn.grid(row=11, columnspan=2, sticky=EW)

# Makes a button that checks the answer
btn = Button(root, text="CHECK ANSWER", bg="darkblue", fg="white",
command=checkanswer)
btn.grid(row=13, columnspan=2, sticky=EW)

#HOW CAN I CENTRE THE TEXT???
txt = Text(root, width=35, height=8, wrap=WORD, font=("arial", 24, "bold"))
txt.grid(row=12, columnspan=2, sticky=EW )

blankline3 = Label(root, text = "", bg = "white")
blankline3.grid(row=17, sticky='ew')

scorelab = Label(root, text="Score", bg="green", fg="white", font=("arial",
20, "bold"))
scorelab.grid(row=18, column=0, sticky=E)

totalLab = Label(root, text="Out of", bg="purple", fg="white",
font=("arial", 20, "bold"))
totalLab.grid(row=19, column=0, sticky=E)

wronglab = Label(root, text="Mistakes", bg="red", fg="white",
font=("arial", 20, "bold"))
wronglab.grid(row=20, column=0, sticky=E)

percentlab = Label(root, text="Percentage", bg="aqua", fg="white",
font=("arial", 20, "bold"))
percentlab.grid(row=21, column=0, sticky=E)

def viewSC():
global score
#scoreViewLab=Label(root, scoreView, textvariable=scoreView)
scoreViewLab = Label(root, text=score, fg="black", bg="grey",
font=("arial", 20, "bold"))
scoreViewLab.grid(row=18, column=1, sticky=W)

def viewTotal():
global total
#scoreViewLab=Label(root, scoreView, textvariable=scoreView)
totalViewLab = Label(root, text=total, fg="black", bg="grey",
font=("arial", 20, "bold"))
totalViewLab.grid(row=19, column=1, sticky=W)

def viewWrong():
global wrong
    global mistakes

#scoreViewLab=Label(root, scoreView, textvariable=scoreView)
   

Re: [Tutor] Times Tables Program that constantly tells you that you are wrong!

2018-08-15 Thread Matthew Polack
Thanks Alan and Peter,

Really appreciate your replies. Will try this out tomorrow and see if I can
get it to work.

I keep googling things myself...but with my 'beginner' status sometimes
struggle to understand the solutions out therebut in tiny steps am
making progress!

Certainly know a lot more than when I started 4 weeks ago!

Thank you so much for your support and time replyingit is very
encouraging.

- Matthew Polack

Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au

On Wed, Aug 15, 2018 at 8:10 PM, Alan Gauld via Tutor 
wrote:

> On 15/08/18 10:18, Peter Otten wrote:
> > Matthew Polack wrote:
> >
> >> *Question 2:*
> >> Is there a way to centre text within the text frame? I can change the
> font
> >> and size...but don't know how to centre it?
> >
> > Ok, I wanted to know it myself, and found
> >
> > https://stackoverflow.com/questions/42560585/how-do-i-
> center-text-in-the-tkinter-text-widget
>
> Well done Peter. I've looked for ways to do this
> (and other format tricks)  several times and
> failed. I never thought of looking at tags though...
>
> Using the string methods as I suggested relies on
> using monospace fonts, and splitting the text
> manually into lines of appropriate length - a major
> pain.
>
> This works with proportional fonts and long text too.
> So much better.
>
> Thanks again for your superior google skills :-)
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Times Tables Program that constantly tells you that you are wrong!

2018-08-15 Thread Matthew Polack
Hi,

A small group of students and I are making steady progress learning Python.
Thanks for the people here who have helped us!

I have an problem with my simple 'Times Tables Program'.

The 'Make Problem' function works fine...it can generate a random problem
and place it in a variable called "answer"...which I've made global because
it needs to be used in the 'Check answer' function.

The trouble is the program is unable to tell you that you are righteven
when you type in the correct answer.

Here is the full code:

from tkinter import *

import random

answer = "global"

def makeproblem():
# deletes anything in text box from location 00 to the end
txt.delete(0.0, 'end')
sentence = "Your first problem is "

number1 = random.randint(2,12)
number2 = random.randint(2,12)
answer = number1 * number2
txt.insert(0.0, sentence)
txt.insert(2.2, number1)
txt.insert(3.3, " x ")
txt.insert(4.4, number2)

def checkanswer():
# deletes anything in text box from location 00 to the end
txt.delete(0.0, 'end')

# checks for what is written in answerbox
response = int(answerbox.get())
if response == answer:
result = "Great Job!"
score = int(score + 1)
else :
result = "Sorry...you were wrong"
txt.insert(0.0, result)
txt.insert(1,1, "Score is")
txt.insert(2,2, score)

root = Tk()
root.geometry("640x640+0+0")
root.title("Times Tables")


timeslabel = Label(root, text="Times Tables Practice", fg="white", bg="blue",
font=("arial", 36, "bold"))
timeslabel.grid(columnspan=12, sticky='ew')
instruction = Label(root, text="Please click on the button to generate a
problem", fg="blue", bg="white", font=("arial", 16, "bold"))
instruction.grid(row=2, columnspan=20)

blankline = Label(root, text = "", bg = "white")
blankline.grid(row=12, sticky='ew')

# Makes an entry box with the variable of 'answerbox'
answerbox = Entry(root, bg="aqua", font=("arial", 24, "bold"))
answerbox.grid(row=15, columnspan=2, sticky=EW)

# Makes a button that generate the Times Tables problem
btn = Button(root, text="GENERATE PROBLEM", bg="blue", fg="white", command=
makeproblem)
btn.grid(row=11, columnspan=2, sticky=EW)

# Makes a button that checks the answer
btn = Button(root, text="CHECK ANSWER", bg="darkblue", fg="white", command=
checkanswer)
btn.grid(row=13, columnspan=2, sticky=EW)

#HOW CAN I CENTRE THE TEXT???
txt = Text(root, width=35, height=10, wrap=WORD, font=("arial", 24, "bold"))
txt.grid(row=12, columnspan=2, sticky=EW )

root.mainloop()


*Question 1:*

*Why cant the program check if 'answer' variable is correct?*

lib\tkinter\__init__.py", line 3269, in insert
self.tk.call((self._w, 'insert', index, chars) + args)
_tkinter.TclError: bad text index "1"

*Question 2:*
Is there a way to centre text within the text frame? I can change the font
and size...but don't know how to centre it?

txt = Text(root, width=35, height=10, wrap=WORD, font=("arial", 24, "bold"))
txt.grid(row=12, columnspan=2, sticky=EW )


*Question 3:*

My 'Score' check idea..may not actually work...haven't been able to get
that far yet though!

Thanks so much for any clues.

- Matthew Polack







Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax question

2018-08-14 Thread Matthew Polack
Just a quick 'Thank you' for this advice the other day Alan and
Abdur-Rahmaan.

Greatly appreciated as we work together with our students here.

Thank you.

Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au

On Thu, Aug 9, 2018 at 6:38 PM, Alan Gauld via Tutor 
wrote:

> On 09/08/18 05:10, Matthew Polack wrote:
>
> > I'm trying to configure a button that prints a variable and calls a
> > function at the same time...but I can't figure out how to get the syntax
> > right...or if this is even possible:
> Of couse its possible just wrap it in a higher level function:
>
> def newfunc():
>print(variable)
>callFunction()
>
> > print("You have selected to convert "), croptype
>
> The crop type needs to be inside the parens
> if you want it printed. That's the syntax error.
>
> If you are trying to call a function called croptype
> then you need to put it on a separate line and lose the ,
> and add parens.
>
>
> > code for this part says;
> >
> > def wheatwords():
> > print("You have selected to convert "), croptype
> > price = int(float(input("What is the current price?")))
> > amount = int(input("\n How much grain in metric tonnes?"))
> > print("This is")
> > print(price * amount, "Metric Tonnes")
> >
>
> I'll assume the lack of indentation is an email formatting
> issue. Did you post in plain text?
>
>
> > wheatbutton = Button(root, text="Wheat", fg="black", bg="yellow")
> > wheatbutton.configure(croptype="wheat", command=wheatwords)
>
> You set croptype to "wheat" but croptype is not an attribute
> of Button. You can't just add arbitrary attributes you need
> to use the ones that the object supports. You can see them
> by using help(). For example:
>
> >>> help(tk.Button)
>
> Help on class Button in module tkinter:
>
> class Button(Widget)
>  |  Button widget.
>  |
>  |  Method resolution order:
>  |  Button
>  |  Widget
>  |  BaseWidget
>  |  Misc
>  |  Pack
>  |  Place
>  |  Grid
>  |  builtins.object
>  |
>  |  Methods defined here:
>  |
>  |  __init__(self, master=None, cnf={}, **kw)
>  |  Construct a button widget with the parent MASTER.
>  |
>  |  STANDARD OPTIONS
>  |
>  |  activebackground, activeforeground, anchor,
>  |  background, bitmap, borderwidth, cursor,
>  |  disabledforeground, font, foreground
>  |  highlightbackground, highlightcolor,
>  |  highlightthickness, image, justify,
>  |  padx, pady, relief, repeatdelay,
>  |  repeatinterval, takefocus, text,
>  |  textvariable, underline, wraplength
>  |
>  |  WIDGET-SPECIFIC OPTIONS
>  |
>  |  command, compound, default, height,
>  |  overrelief, state, width
>  |  
>
> Shows the valid options available.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Syntax question

2018-08-09 Thread Matthew Polack
Hi,

I'm trying to configure a button that prints a variable and calls a
function at the same time...but I can't figure out how to get the syntax
right...or if this is even possible:

print("You have selected to convert "), croptype

I've tried various combinations of the above...but can't get it to
work...any clues as to what I should do:


Thanks,

Matt

code for this part says;

def wheatwords():
print("You have selected to convert "), croptype
price = int(float(input("What is the current price?")))
amount = int(input("\n How much grain in metric tonnes?"))
print("This is")
print(price * amount, "Metric Tonnes")

wheatbutton = Button(root, text="Wheat", fg="black", bg="yellow")
wheatbutton.configure(croptype="wheat", command=wheatwords)


Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to add an Image in Grid mode with Python and Tkinter?

2018-07-31 Thread Matthew Polack
Thanks Alan and Peter for the comprehensive replies...that gives me some
good 'homework' to do and clarity on how to go about it.

Much appreciatedwill spend some time now getting my head around it.

Thanks so much.

- Matthew Polack

Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au

On Tue, Jul 31, 2018 at 4:26 AM, Alan Gauld via Tutor 
wrote:

> On 30/07/18 08:24, Matthew Polack wrote:
>
> > I'm trying to simply add an image to our program to make the GUI more
> > interesting...but most of the tutorials describe using the 'Pack'
> > method not the grid method of layout...
>
> That's completely irrelevant since you can add images to widgets
> regardless of the layout manager used. In most cases you will
> want to use a PhotoImage widget to do it though.
>
> > and apparently you cannot use 'Pack' and 'Grid' in the one program...
>
> Yes you can just not in the same container.
> For example a common strategy for building forms based apps
> is to have a menubar on top with a toolbar frame packed below
> with a data frame packed below that and finally a status
> bar frame packed at the bottom.
>
> Within those frames you use the packer for the toolbar buttons,
> and for the status bar text. Then you use the grid layout
> manager to display the data entry widgets in the centre panel.
>
> So at each container(usually a Frame) level you can only have
> a single layout manager, but inside each nested container
> you can choose to use the same or a different manager.
>
> And remember there are more than just pack and grid, there
> are also place and form(in Tix) (and you can write your own
> if you are really keen!)
>
> > Can anyone explain how I could add an image to this program? Or show me
> an
> > example of a simple program that lets someone simply add an image and use
> > the grid layout in combination.
> import tkinter as tk
>
> top = tk.Tk()
> tk.Label(image = "foo.img").grid(row=0,column=0)
>
> top.mainloop)()
>
>
> Thats about as simple as it gets. But the img file must
> be in Tk compatible format.
>
> More generally, use a PhotoImage:
>
> import tkinter as tk
>
> top = tk.Tk()
> lbl = tk.Label()
> lbl.grid(row=0,column=0)  #could as easily use pack() or place()
>
> img = tk.PhotoImage(file="/path/to/myimg.gif")
> lbl['image'] = img
>
> top.mainloop)()
>
> But to get more sophisticated you really want to look
> into the PIL/Pillow library and its integration with
> Tkinter via the image class. Also look at how the Text
> and Canvas widgets deal with images because its slightly
> more complex than a simple Label or Button.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How to add an Image in Grid mode with Python and Tkinter?

2018-07-30 Thread Matthew Polack
Hi,

Steadily trying to learn Python and Tkinter here with our students...

Am working on a simple 'Price of Cereal Crop' calculatorand have made a
start with the code below...

I'm trying to simply add an image to our program to make the GUI more
interesting...but most of the tutorials describe using the 'Pack'
method not the grid method of layout...

and apparently you cannot use 'Pack' and 'Grid' in the one program...

Can anyone explain how I could add an image to this program? Or show me an
example of a simple program that lets someone simply add an image and use
the grid layout in combination.

Thanks for any clues at all!

- Matt

from tkinter import *
root = Tk("Crop Calculator")

# abutton = Button(root, text="Crop Prices in Australia")

#Main Heading Labels
croplabel = Label(root, text="Crop Prices in Australia", fg="white", bg=
"green")
instruction = Label(root, text="Please select from the following crops", fg=
"green", bg="white")
blanklabel = Label(root, text="", fg="green", bg="white")
blanklabel2 = Label(root, text="", fg="green", bg="white")
statusbar = Label(root, text="Copyright 2018", fg="white", bg="black",
relief='sunken')

#Answerlabel
answerlabel=Label(root, text="wheatwords")

# abutton.pack(side='left', fill='both', expand=True)
croplabel.grid(columnspan=12, sticky='ew')
instruction.grid(row=1, columnspan=12, sticky='ew')
blanklabel.grid(row=2, columnspan=12, sticky='ew')
statusbar.grid(row=12, columnspan=12, sticky='ew')
blanklabel2.grid(row=11, columnspan=12, sticky='ew')


#List of Crops
wheatlabel = Button(root, text="Wheat", fg="black", bg="yellow")
peaslabel = Button(root, text="Peas", fg="white", bg="green")
lupenslabel = Button(root, text="Lupens", fg="white", bg="brown")
barleylabel = Button(root, text="Barley", fg="white", bg="orange")
canolalabel = Button(root, text="Canola", fg="white", bg="red")
sorghumlabel = Button(root, text="Sorghum", fg="white", bg="ivory3")

# Grid positioning of crops.
wheatlabel.grid(row=4, column=1, sticky='ew')
peaslabel.grid(row=4, column=7, sticky='ew')
lupenslabel.grid(row=5, column=1, sticky='ew')
barleylabel.grid(row=5, column=7, sticky='ew')
canolalabel.grid(row=6, column=1, sticky='ew')
sorghumlabel.grid(row=6, column=7, sticky='ew')

# Definitions

def wheatwords():
print("Button one was pushed")

wheatlabel.configure(command=wheatwords)


root.mainloop()

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Stuck on some basics re floats

2018-07-18 Thread Matthew Polack
Hi,

I'm a teacher trying to learn Python with my students.

I am trying to make a very simple 'unit calculator' program...but I get an
error ..I think python is treating my num1 variable as a text string...not
an integer.

How do I fix this?

Thanks!

- Matt

print ("How many inches would you like to convert? ")
num1 = input('Enter inches here')
print ("You have entered",num1, "inches")
convert = num1 * 2.54
print ("This is", convert, "centimetres")


Traceback (most recent call last):
  File "convert.py", line 10, in 
convert = num1 * 2.54
TypeError: can't multiply sequence by non-int of type 'float'


Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.pol...@htlc.vic.edu.au

w. www.htlc.vic.edu.au

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529** and destroy the original message.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor