tkinter - Python post increment variable in function call -
premise: trying make bunch of buttons in tkinter , put them in grid layout 1 after other. don't want hard code each grid value way can add more buttons later ease.
my first thought to:
button(root, text = "example", command = self.example_action).grid(row = count++) but did not work, did searching , found python not have pre or post increment operator (behaviour of increment , decrement operators in python). next thought to:
button(root, text = "example", command = self.example_action).grid(row = count = count + 1) this gives: syntaxerror: invalid syntax
so other splitting code onto 2 lines (use variable update on next line) there way on 1 line make code more beautiful?
thanks, joshua
i suppose use generator. initialize count like:
count = itertools.count() then can following as like
python 2.x:
button(root, text = "example", command = self.example_action).grid(row = count.next()) python 3.x:
button(root, text = "example", command = self.example_action).grid(row = next(count)) but wouldn't
Comments
Post a Comment