[Tutor] Python

2016-10-24 Thread Kadir Sertcanli
Hi! I have a function that I want to plot depending on a parameter (’a’), I 
looked in the beginners guide but couldn’t fint what I wanted. I know how to 
put the axis etc. but I don’t know how to involve my function which is 
V=-(ba^-1 + ca^2) where I have different values for b and c, so the function I 
want to plot is depending on a. 

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


Re: [Tutor] Python

2016-10-24 Thread Alan Gauld via Tutor
On 24/10/16 15:40, Kadir Sertcanli wrote:
> Hi! I have a function that I want to plot depending on a parameter (’a’), 

OK, But you will need to give us some more details.

> I looked in the beginners guide 

Which beginner's guide are you using?
Plotting is not something normally covered in a Python beginner's
guide - it's not part of standard Python, you usually need some
extra modules to do that.

> I know how to put the axis etc. 

Which plotting module are you using?
Or are you trying to do it using a GUI toolkit (if so which one?)?

> but I don’t know how to involve my function which is 
> V=-(ba^-1 + ca^2) where I have different values for b and c
> so the function I want to plot is depending on a. 

Normally you would generate a set of data pairs and then plot those.
Do you know how to create a list of values based on your input 'a' values?

for example if I wanted to plot the first 10 integer squares
I'd generate a list of values something like:

data = [(n,n**n) for n in range(10)]

That would give me a data list that looked like:

[(0,0),(1,1),(2,4),(3,9),...(9,81)]

I could then plot each pair on a graph or chart of some sort.

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

2016-10-24 Thread Steven D'Aprano
On Mon, Oct 24, 2016 at 04:40:08PM +0200, Kadir Sertcanli wrote:

> Hi! I have a function that I want to plot depending on a parameter 
> (’a’), I looked in the beginners guide but couldn’t fint what I 
> wanted. I know how to put the axis etc. but I don’t know how to 
> involve my function which is V=-(ba^-1 + ca^2) where I have different 
> values for b and c, so the function I want to plot is depending on a.

How are you plotting the function? What software are you using? How do 
you put the axis on? 

What part do you not understand? Show us the code that you have. Don't 
expect us to guess what you are doing.



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


Re: [Tutor] Python

2016-10-24 Thread Joaquin Alzola
>Hi! I have a function that I want to plot depending on a parameter (’a’), I 
>looked in the beginners guide but couldn’t fint what I wanted. I know how to 
>put the axis etc. but I don’t know how to involve my function which is 
>V=-(ba^-1 + ca^2) where I have >different values for b and c, so the function 
>I want to plot is depending on a.

You need to put your code.
This email is confidential and may be subject to privilege. If you are not the 
intended recipient, please do not copy or disclose its content but contact the 
sender immediately upon receipt.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python v3 Tkinter GUI program

2016-10-24 Thread Elliott Andrews
Hi there, I am making a program in python based on a Subway operation. All
descriptions and comments codes are provided in the attached program. I've
been using IDLE to run the program and it seems to work the way I want it
too.

However I have heard from many, that global variables are bad practise in
any programming language, and so I want to basically replace all my global
variables with another variable that does the same thing.

The problem is, some data is entered and then when the data is submitted,
the GUI window terminates and automatically re-opens for another data
entry. I need some sort of variable to store some data while the program
resetts itself.

Sorry is this sounds really broad, and I am happy to clarify and points.
''' Author: Elliott Andrews, Date: 22/09/16, Programmed with: IDLE 3.5.1 via 
Python 3.5.1 and Tk 8.6.4

Program Title: "Phone Ordering System for SUBS R US."

Program Description: This program is designed for a company (e.g Subway) to 
enter in an order for a sub as a phone operator. The phone operater will ask for
customer infomation, ingedients to be put in the sub and then order it. The 
phone operator will then ask the customer if they wish to cancel the order and 
if they
want to order another sub. After all subs have been ordered, the phone operator 
will tell the customer the total cost of all the subs orders and then exit the 
prgoram'''

from tkinter import * #Importing GUI from tkinter library to display in window.
import time #Importing time controls for diagnostic messages (readability).

#Global variables (major) have to be used to pass 'cancelled' and 'total_cost' 
through whole application. 
#This will ensure when window is told to destory, variables will be kept for a 
maximum of 5 future orders and will avoid any 'Traceback' errors.
#Not using global variables or other means such as (.get) will not work because 
when window is told to destory, a new window instance is created, defaulting 
and resetting orig variables.
global cancelled 
global total_cost
total_cost = 0 #Setting total cost (for all orders - max 5) to 0.

class Startup: #First class 'Startup' which will run diagnostic checks to make 
sure program will run.

print("Current python version: 3.5.1 \nTk version: 8.6.4") #Recommended 
version to run python and tkinter in.

if total_cost != 0: #If total_cost is not equal to 0, then... This 
variable has to be set to 0, as it will be added too, each time a order is 
added.
print("Sorry, the application failed to start. Please make sure 
you have the latest python version and try again. \n Error: Failed to reset top 
variabe (Total_Cost)")
else: #Otherwise, continue as normal.
print("Application starting...")
time.sleep (2) #Giving time for operator/user to see the status for 
application startup.

class GUI(Frame, Startup): #Second class 'GUI' which will run the main display 
(visual elements and will continue from first class).
def __init__(self, master): #Initalising the GUI application.
 
super(GUI, self).__init__(master) #For use with lots of mutiple 
instances of __init__. Future use for parenting within 'master'.
self.grid() #Defining layout for GUI (grid method), could also use pack.
self.clear_variables() #Stating all functions with 'def'...
self.cancel()
self.create_widgets()
self.check_address()
self.show_order()
self.close_window()

def close_window(self): #Defining the process to close the window, reset 
cancelled variable equal to 0, then quit.

global cancelled
cancelled = 0
root.quit() #Will prepare a quit function if needed.

def clear_variables(self): #Defining the process to set all other minor 
variables to proper type and to set them to None or 0 where appropriate.

self.ordertype = StringVar() #StringVar is ideal for letters...
self.cusName = StringVar()
self.cusAddress = StringVar()
self.cusPhone = StringVar() #Can use IntVar for phone number, but for 
textbox display only, StringVar is ok.
self.breads_var = StringVar()
self.cheeses_var = StringVar()
self.sauces_var = StringVar()

self.ordertype.set (None) #Has a 'None' value, similar to 'Null'.
self.cusName.set (None)
self.cusAddress.set (None)
self.cusPhone.set (None)
self.breads_var.set (None)
self.cheeses_var.set (None)
self.sauces_var.set (None)
self.cost = 0 #Since self.cost is to be a integer, integer operations 
must be used
root.quit() #Will prepare a quit function if needed.

def cancel(self): #Defining the process for cancelling the order, to set 
all other minor variables to proper type and to set them to None or 0 where 
appropriate.
#This process allows orders that have been cancelled to continue the 
program.
sel

Re: [Tutor] PyctvhccTV TtV v.:vgvon v3 Tkinter GgUI program

2016-10-24 Thread Jay Talbot
Qk.   vv"::.:

On Oct 24, 2016 6:08 PM, "Elliott Andrews" 
wrote:

Hi there, I am making a program in python based on a Subway operation. All
descriptions and comments codes are provided in the attached program. I've
been using IDLE to run the program and it seems to work the way I want it
too.

However I have heard from many, that global variables are bad practise in
any programming language, and so I want to basically replace all my global
variables with another variable that does the same thing.

The problem is, some data is entered and then when the data is submitted,
the GUI window terminates and automatically re-opens for another data
entry. I need some sort of variable to store some data while the program
resetts itself.

Sorry is this sounds really broad, and I am happy to clarify and points.

___
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] Python v3 Tkinter GUI program

2016-10-24 Thread Alan Gauld via Tutor
On 24/10/16 22:36, Elliott Andrews wrote:
> Hi there, I am making a program in python based on a Subway operation. All
> descriptions and comments codes are provided in the attached program.

Normally attachments are deleted by the server although yours
seems to have gotten through (to me at least).

Its best to post code in the body of the mail although in
your case that's a lot of code so maybe a pastebin would
be better.

Anyways

> been using IDLE to run the program and it seems to work the way I want it
> too.

OK, But you should always test GUIs outside of an IDE, after all
thats how they will likely be run in the real world and while
IDEs are great development tools they often distort the environment
in subtle ways that can change how things behave.

> However I have heard from many, that global variables are bad practise in
> any programming language, and so I want to basically replace all my global
> variables with another variable that does the same thing.

You need to understand why they are bad practice. In the real world most
non-trivial programs will have a few global variables (even
if its just an instance of a top level class).

The main problems with globals is that it is very hard to keep track
of what is changing them and when. Also they make your code
almost unusable in any other context since you need to replicate
all the variables.

One trivial way to do it in your case is to put them inside
the GUI class. That's still got a lot of the same problems as
globals but at least you can reuse the class without issues.

[incidentally you don't need to label your global variables
as global outside of the functions where they are used. The
global keyword is a way of indicating which globals are used
by a given function, it is not an indication to the rest
of the program that a variable is global.]

> The problem is, some data is entered and then when the data is submitted,
> the GUI window terminates and automatically re-opens for another data
> entry. I need some sort of variable to store some data while the program
> resetts itself.

The usual solution in GUI programs is not to kill the window
but merely to hide it. You can then change the display values
and reshow it again as needed. That way the "global" variables
are still available.

In Tkinter the hide method is called withdraw(). To redisplay
it use the deiconify() method, and if necessary the lift()
method to raise it to the top of the window stack.

I can't help but mention the way you build your message strings.
You should look at string formatting, it is usually a cleaner
and more efficient solution that using the += operator on
strings. The latter involves an awful lot of copying of
strings and while you only do it about 20 times it would be
better practice to insert the data elements using formatting.

There are a lot of other comments I could make about the code
but for now those pointers should move you forward.

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


[Tutor] Attaching program text to messages (was: Python v3 Tkinter GUI program)

2016-10-24 Thread Ben Finney
Alan Gauld via Tutor  writes:

> On 24/10/16 22:36, Elliott Andrews wrote:
> > All descriptions and comments codes are provided in the attached
> > program.
>
> Normally attachments are deleted by the server although yours
> seems to have gotten through (to me at least).

I think because it is (declared by Elliott's mail user-agent to be) a
text attachment, it survives to the mailing list.

> Its best to post code in the body of the mail although in your case
> that's a lot of code so maybe a pastebin would be better.

A text attachment (provided you ensure it is declared that way, as
Elliott's message did) seems a better way. If it fails, we all know
immediately, and it can be retried.

A pastebin's failure mode (some reader can't access for whatever reason)
is more likely to appear later, when someone wants to refer back to the
message. So I'd say that is inferior to attaching the program text.

-- 
 \  “Now Maggie, I’ll be watching you too, in case God is busy |
  `\   creating tornadoes or not existing.” —Homer, _The Simpsons_ |
_o__)  |
Ben Finney

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


Re: [Tutor] Python v3 Tkinter GUI program

2016-10-24 Thread Alan Gauld via Tutor
On 24/10/16 22:36, Elliott Andrews wrote:

> Sorry is this sounds really broad, and I am happy to clarify and points.

Sorry I just noticed another point that I can't overlook.

You have code/comment:

root = Tk() #The actual statment which opens the window,
toplevel = root.winfo_toplevel() #Setting window header
   # to attach to top of screen (first half of
   # making window maximised)

This is not how best to maximise a window.
First you should find that toplevel is the same as root.

ie
toplevel == root is True.

So instead of:
toplevel.wm_state('zoomed') #Setting inner window to stretch

You should be able to do
root.wm_state('zoomed')
instead.

Although you don't strictly need the wm_ prefix since Tkinter
provides the state() shortcut:

root.state('zoomed')

Except that doesn't work for me and I get an error
about 'zoomed' being an invalid choice. The more usual
way is to set the geometry to the screen size:

top = Tk()
top.withdraw()  # hide the window
sh = top.winfo_screenheight()
sw = top.winfo_screenwidth()
top.geometry("%sx%s" % (sw,sh)) # resize it to full screen
top.deiconify()  # show the resized window

[The hide/show sequence is because if the window layout
is complex it will be redrawn much more quickly and without
any flickering if you hide/show.]

Finally, be aware that maximising a window is considered
bad practice in modern GUI design for two reasons:
1) Modern OS allow users to multi-task and grabbing the
whole screen to yourself is a bit greedy and makes it very
annoying to the user. I have a 32 inch monitor precisely
because I want to see (say) my browser, email and
spreadsheet all at the same time!
2) Given that screens can range widely in size it is
almost impossible to guarantee that your widget layouts
and fonts will be usable on every screen. (compare a
1024x768 netbook display with a 4096x2160 4K video monitor)

HTH
-- 
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] Attaching program text to messages

2016-10-24 Thread Alan Gauld via Tutor
On 25/10/16 00:01, Ben Finney wrote:

> I think because it is (declared by Elliott's mail user-agent to be) a
> text attachment, it survives to the mailing list.

That might be the reason.

> A text attachment (provided you ensure it is declared that way, as
> Elliott's message did) seems a better way. If it fails, we all know
> immediately, and it can be retried.

That's true if it always survives. It will be interesting to see
if the attachment is accessible from the archives... OK, It shows
the text appended to the message so that does indeed seem the best option.

Now, how do we educate everyone on how to specify and use a text
attachment? (This is a serious question BTW since we can add it
to the tutor welcome/usage message.)

-- 
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] Attaching program text to messages

2016-10-24 Thread Ben Finney
Alan Gauld via Tutor  writes:

> Now, how do we educate everyone on how to specify and use a text
> attachment? (This is a serious question BTW since we can add it
> to the tutor welcome/usage message.)

That depends on who's included in “everyone” :-)

If it includes people who don't wish to change their email client, I
think that may be impossible. Some email clients (e.g. Microsoft
Outlook) are notoriously bad at handling attachments, so if you're not
willing to tell such people “switch to a better client” then you may not
be able to include them.

As well as telling people to avoid some terrible email clients, you're
talking about educating people on how to use their email client's
specific features.

Does “everyone” include people who are just trying to post a message
here for the first time and aren't ready to gat a lecture on what an
email client even is? (The proportion of people using email without any
awareness of what program they're even using is surprisingly high, so a
document saying “Follow the instructions from the section that applies
to your specific email client” will not be of use to those people.)

It's a difficult problem: email should be simple to use correctly by
default, but people's email clients – that many of them didn't actively
select – are in varying states of brokenness, before they even get any
information from us about what to do.

-- 
 \“Intellectual property is to the 21st century what the slave |
  `\  trade was to the 16th.” —David Mertz |
_o__)  |
Ben Finney

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