[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] Syntax question

2018-08-09 Thread Alan Gauld via Tutor
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


[Tutor] Fwd: Syntax question

2018-08-09 Thread Abdur-Rahmaan Janhangeer
missed reply all

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ
Mauritius

-- Forwarded message -
From: Abdur-Rahmaan Janhangeer 
Date: Thu, 9 Aug 2018, 11:56
Subject: Re: [Tutor] Syntax question
To: Matthew Polack 


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

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ
Mauritius
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor