On 18/05/15 19:27, cartman6921 wrote:
*Below is a code made by me in 5 minutes, I am new to Tkinter so am kinda
noobish.

We all have to start somewhere.

Unfortunately there are a few issues with your code.
I'll try to deal with them as we go through.

from tkinter import *
root=Tk()

root.title("Lemonade Stand")
root.geometry("500x500+500+300")

lemon=0

def BuyLemon():
     str(lemon)+str(1)
     print(lemon)

This function doesn't do what you think it does.
The second line takes the string representation of
lemon ('0') and adds the string representation of
1 ('1') using string concatenation to produce '01'

Then it throws it away.
Finally it prints lemon which remains unchanged as zero.

You need to have an assignment inside the function
that modifies lemon. But because you are modifying a
global variable you need to declare lemon as global
inside the function. So you get:

def buyLemon():
    global lemon
    lemon = str(lemon) + str(1)
    print (lemon)

However if you just use that function you will wind
up, after 4 presses, with '01111' which is not what
you want.

Instead of converting to strings just add the numbers:

def buyLemon():
    global lemon
    lemon +=1
    print (lemon)

button = Button(root,text="Buy Lemon x1", command=BuyLemon)
button.pack()

root.mainloop()

Once you get that working your next step should be to get
the output printed on the GUI rather than the console. For
that you should probably start with a Label widget. You
can then assign the string representation of lemon to the
text attribute of the label.

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

Reply via email to