counter with tkinter
so if i have this code
from Tkinter import *
admin = Tk()
a = []
page = 1
def numup():
page = page + 1
page = str(page)
print pa开发者_JAVA技巧ge
a.append(page)
button = Button(admin, text='number up one', command=numup)
button.pack(side=RIGHT)
admin.mainloop()
but it doesent count.
please dont be rude i just finished a huge program and this be the finishing touches. thanks
You need to use global page
to be able to increment page from within the numup() function. That should fix it:
def numup():
global page
page += 1
print page
a.append(page)
Ok you can use lambda:
if needed so you can pass arguments to your function, I edited your program with the fix, I have tested it too, good luck!:
from Tkinter import *
admin = Tk()
a = []
page = 1
def numup(page):
page = page + 1
page = str(page)
print page
a.append(page)
button = Button(admin, text='number up one', command=lambda: numup(page))
button.pack(side=RIGHT)
admin.mainloop()
精彩评论