Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-17 Thread Palm Tree
On 16 Apr 2017 10:01, "Palm Tree"  wrote:

Sorry for late reply.

We usually organise python challenges.

Once we organise a gui calculator challenge.

You can view the submissions on my blog here:
https://abdurrahmaanjanhangeer.wordpress.com/gui-py-
calculator-challenge-19-1-17/

On 16 Apr 2017 09:50, "Alex Kleider"  wrote:

> On 2017-04-15 01:04, Alan Gauld via Tutor wrote:
>
>
>
>> Finally, if you can find a copy of my recent book "Python Projects"
>> there is a rolling project within that which demonstrates how
>> the same logic code can be used to build a CLI, a GUI and a
>> Web app. [ In fact it goes even further by demonstrating how
>> to break an app into 3 tiers - data, logic and UI - which
>> is industry best practice, but usually overkill for small
>> projects.]
>>
>
> Thanks, Alan, for the guidance.  As it happens, I have a copy of your
> Python Projects" book- time to get it off the shelf and have a closer look!
> Alex
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-15 Thread Alex Kleider

On 2017-04-15 01:04, Alan Gauld via Tutor wrote:




Finally, if you can find a copy of my recent book "Python Projects"
there is a rolling project within that which demonstrates how
the same logic code can be used to build a CLI, a GUI and a
Web app. [ In fact it goes even further by demonstrating how
to break an app into 3 tiers - data, logic and UI - which
is industry best practice, but usually overkill for small
projects.]


Thanks, Alan, for the guidance.  As it happens, I have a copy of your 
Python Projects" book- time to get it off the shelf and have a closer 
look!

Alex
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-15 Thread Sri Kavi
On Wed, Apr 5, 2017 at 12:42 AM, Alan Gauld via Tutor 
wrote:

> On 04/04/17 17:55, Lisa Hasler Waters wrote:
>
> > A middle school student of mine created a program to calculate simple and
> > compound interest. He built it in PyCharm EDU using a Mac running
> 10.11.6.
> >
> > He would like to create a GUI to run this program. Please, can you advise
> > on how he could build this?
>
> He could use Tkinter, or he could create an HTML screen and
> write a small server using a Framework like Flask.
>
> Whatever he does he will need to dsepsarate his UI from his
> logic - a good programming skill regardless of UI.
>
> So his first step should be to create a CLI UI on top of
> his existing code such that none of hi functions contain
> print() or input() statements, they should all be in
> new UI code.
>
> The next step is to convert it to event driven style.
> For this code that should almost be a done deal.
>
> Finally decide on his GUI/Web framework and do a tutorial
> to get up to speed and fit his new event-driven backend
> code into that.
>
> > Here is his code:
> >
> > def simple(m, t, r):
> > r = r/100
> > print("The interest is {} and the total is {} ".format(r*m*t,
> m+r*m*t))
>
> Should return a value not print a message
>
> > def compound(m, t, r):
> > morg = m
> > r = r/100
> > for x in range(0, t):
> > m = m*r+m
> > print("The interest is {} and the total is {} if compounded
> > yearly.".format(m-morg, m))
> > m = morg
> > r = r/12
> > for x in range(0, t*12):
> > m = m*r+m
> > print("The interest is {} and the total is {} if compounded
> > monthly.".format(m-morg, m))
> >
>
> Possiobly should be two separate methods, and definitely
> should be returning values not printing stuff.
>
>
> > choice = str(input("Would you like to use simple or compound interest?
> "))
> > m = int(input("Input the amount of money you would like to deposit
> > (don't use the $ symbol): "))
> > t = int(input("Input the amount of time you will be keeping your money
> > in the bank (in years): "))
> > r = int(input("Input the interest rate the bank offers (don't use the
> > % symbol): "))
> >
> > if choice == 'simple':
> > simple(m, t, r)
> > elif choice == 'compound':
> > compound(m, t, r)
> > else:
> > print("Your input is invalid")
>
> This needs to turn into a UI event loop which it almost is
> but with no loop and no exit option.
>
>

I’m feeling inspired by Alan Gauld’s reply and using this as an opportunity
to learn Flask.  Thank you, Alan. I have written a similar calculator
program and created two separate versions of CLI UI using argparse and
Google’s Python Fire. I’m trying to create an HTML screen and use my Python
script that imports the Flask module which will pass data to the HTML file.
When the web page is loaded, it should run the code associated with the
page.


Once I can make this work, I will submit it for your kind comments :)

Sri
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-15 Thread Alan Gauld via Tutor
On 15/04/17 03:38, Alex Kleider wrote:

>> Whatever he does he will need to separate his UI from his
>> logic - a good programming skill regardless of UI.
> 
> Can anyone suggest a good tutorial that explains exactly what this means 
> and how to achieve it?
> (separate UI from logic I mean.)

I don't know of a tutorial as such but the principles are enshrined
in the Model-View-Controller (MVC) design pattern and there are lots
of articles and tutorials on that. One caveat is that there are
almost as many variations on MVC as there are articles so you can expect
some contradiction in the details. That's ok, just focus
on the big ideas.

At the most basic just do as I suggested in the post. Identify the
functions that do the work(the logic) and make sure they take all
of their input via parameters and deliver a result back to the
caller with no UI (eg input() or print()) statements inside
the function.

Then write the code that interacts with the user as a separate
function which calls the logic functions as needed. You should
be able to put the core functions into a separate module and
import that into the UI module/main program. That's quite a
good check that you have made your logic reusable.

This is good practice for all programming projects but its
essential for GUI and Web projects.

Finally, if you can find a copy of my recent book "Python Projects"
there is a rolling project within that which demonstrates how
the same logic code can be used to build a CLI, a GUI and a
Web app. [ In fact it goes even further by demonstrating how
to break an app into 3 tiers - data, logic and UI - which
is industry best practice, but usually overkill for small
projects.]

-- 
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


Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-14 Thread Alex Kleider

On 2017-04-04 12:12, Alan Gauld via Tutor wrote:

On 04/04/17 17:55, Lisa Hasler Waters wrote:

A middle school student of mine created a program to calculate simple 
and
compound interest. He built it in PyCharm EDU using a Mac running 
10.11.6.


He would like to create a GUI to run this program. Please, can you 
advise

on how he could build this?


He could use Tkinter, or he could create an HTML screen and
write a small server using a Framework like Flask.

Whatever he does he will need to dsepsarate his UI from his
logic - a good programming skill regardless of UI.


Can anyone suggest a good tutorial that explains exactly what this means 
and how to achieve it?

(separate UI from logic I mean.)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-05 Thread Lisa Hasler Waters
Wonderful! Thank you all so very much for all this invaluable expertise. We
have a lot of ways to make this work. We are excited to continue learning
so much.

Lisa

On Tue, Apr 4, 2017 at 8:15 PM, Marc Tompkins 
wrote:

> On Tue, Apr 4, 2017 at 9:55 AM, Lisa Hasler Waters 
> wrote:
>
>> Hello Tutor,
>>
>> A middle school student of mine created a program to calculate simple and
>> compound interest. He built it in PyCharm EDU using a Mac running 10.11.6.
>>
>> He would like to create a GUI to run this program. Please, can you advise
>> on how he could build this?
>>
>> Others have mentioned Tkinter and HTML; I''d like to put in my two cents'
> worth for wxPython .  HTML is probably the best
> cross-platform solution, and requires the least extra stuff bolted on, but
> wxPython lets you create desktop apps that look like they were actually
> developed for the computer they run on.
>
> Alan Gauld's comments about separating the GUI from the program logic are,
> as usual, spot-on.
>
>


-- 
Lisa Waters, PhD
Technology Integration
Middle School Coding
Lower School Digital Literacy
Flint Hill School
703.584.2300
*www.flinthill.org* 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-04 Thread Marc Tompkins
On Tue, Apr 4, 2017 at 9:55 AM, Lisa Hasler Waters 
wrote:

> Hello Tutor,
>
> A middle school student of mine created a program to calculate simple and
> compound interest. He built it in PyCharm EDU using a Mac running 10.11.6.
>
> He would like to create a GUI to run this program. Please, can you advise
> on how he could build this?
>
> Others have mentioned Tkinter and HTML; I''d like to put in my two cents'
worth for wxPython .  HTML is probably the best
cross-platform solution, and requires the least extra stuff bolted on, but
wxPython lets you create desktop apps that look like they were actually
developed for the computer they run on.

Alan Gauld's comments about separating the GUI from the program logic are,
as usual, spot-on.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-04 Thread Sri Kavi
On Tue, Apr 4, 2017 at 10:25, Lisa Hasler Waters wrote:

> Hello Tutor,
>
> A middle school student of mine created a program to calculate simple and
> compound interest. He built it in PyCharm EDU using a Mac running 10.11.6.
>
> He would like to create a GUI to run this program. Please, can you advise
> on how he could build this?
>
>
Please take a look at https://wiki.python.org/moin/GuiProgramming and
https://wiki.python.org/moin/TkInter

Hope that helps.

Sri
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-04 Thread Alan Gauld via Tutor
On 04/04/17 17:55, Lisa Hasler Waters wrote:

> A middle school student of mine created a program to calculate simple and
> compound interest. He built it in PyCharm EDU using a Mac running 10.11.6.
> 
> He would like to create a GUI to run this program. Please, can you advise
> on how he could build this?

He could use Tkinter, or he could create an HTML screen and
write a small server using a Framework like Flask.

Whatever he does he will need to dsepsarate his UI from his
logic - a good programming skill regardless of UI.

So his first step should be to create a CLI UI on top of
his existing code such that none of hi functions contain
print() or input() statements, they should all be in
new UI code.

The next step is to convert it to event driven style.
For this code that should almost be a done deal.

Finally decide on his GUI/Web framework and do a tutorial
to get up to speed and fit his new event-driven backend
code into that.

> Here is his code:
> 
> def simple(m, t, r):
> r = r/100
> print("The interest is {} and the total is {} ".format(r*m*t, m+r*m*t))

Should return a value not print a message

> def compound(m, t, r):
> morg = m
> r = r/100
> for x in range(0, t):
> m = m*r+m
> print("The interest is {} and the total is {} if compounded
> yearly.".format(m-morg, m))
> m = morg
> r = r/12
> for x in range(0, t*12):
> m = m*r+m
> print("The interest is {} and the total is {} if compounded
> monthly.".format(m-morg, m))
> 

Possiobly should be two separate methods, and definitely
should be returning values not printing stuff.


> choice = str(input("Would you like to use simple or compound interest? "))
> m = int(input("Input the amount of money you would like to deposit
> (don't use the $ symbol): "))
> t = int(input("Input the amount of time you will be keeping your money
> in the bank (in years): "))
> r = int(input("Input the interest rate the bank offers (don't use the
> % symbol): "))
> 
> if choice == 'simple':
> simple(m, t, r)
> elif choice == 'compound':
> compound(m, t, r)
> else:
> print("Your input is invalid")

This needs to turn into a UI event loop which it almost is
but with no loop and no exit option.


-- 
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