Home Python 3: How do I place an incrementing literal in a loop?
Reply: 0

Python 3: How do I place an incrementing literal in a loop?

user550
1#
user550 Published in May 24, 2018, 4:00 pm

I want to set up a list of buttons inside a loop, with each button's command calling a function with a different value.

for rank in range(21):
    self._rankButton.append(Button(self, text = "Rank " + str(rank),
        command = self._setDice(rank))

self._rankButton[0] should call self._setDice(0)
self._rankButton[1] should call self._setDice(1)
.
.
.
self._rankButton[20] should call self._setDice(20)

the only way I get this to work is by configuring the buttons individually outside the loop

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.40675 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO