Python Forum
conway's game of life
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
conway's game of life
#14
Quote:I guess I could implement that but the +/- 50 also corresponds to the size of the square (not speed).
It was more of a generic concept related to reducing magic numbers in code.

Define speed in one place and the dict never changes.  If you need to change speed you change it in one place.
Something to keep in mind in the future.

As to your question, I don't use tkinter much, but yes.
You could do something like this:
bindings = {"<KeyPress-Up>" : movesquare, "<KeyPress-Down>": movesquare,
            "<KeyPress-Left>": movesquare, "<KeyPress-Right>": movesquare,
            "x": otherkey, "f": otherkey, "r": otherkey}

for binding in bindings:
    canvas.bind_all(binding, bindings[binding])
Also, I question whether or not you need to rebind those every time through the loop.
Once up front should be fine I would think.
Reply


Messages In This Thread
conway's game of life - by hanscvanleeuwen - Nov-25-2016, 07:51 PM
RE: conway's game of life - by Skaperen - Nov-26-2016, 08:25 AM
RE: conway's game of life - by hanscvanleeuwen - Nov-26-2016, 09:33 AM
RE: conway's game of life - by hanscvanleeuwen - Nov-26-2016, 12:24 PM
RE: conway's game of life - by Skaperen - Nov-27-2016, 01:45 AM
RE: conway's game of life - by Mekire - Nov-28-2016, 04:30 AM
RE: conway's game of life - by hanscvanleeuwen - Nov-28-2016, 07:55 AM
RE: conway's game of life - by heiner55 - Nov-29-2016, 02:41 PM
RE: conway's game of life - by hanscvanleeuwen - Nov-30-2016, 01:45 PM
RE: conway's game of life - by hanscvanleeuwen - Dec-07-2016, 02:02 PM
RE: conway's game of life - by Ofnuts - Dec-08-2016, 09:56 PM
RE: conway's game of life - by Mekire - Dec-09-2016, 03:35 AM
RE: conway's game of life - by hanscvanleeuwen - Dec-09-2016, 10:13 AM
RE: conway's game of life - by Mekire - Dec-09-2016, 11:03 AM
RE: conway's game of life - by hanscvanleeuwen - Dec-09-2016, 11:25 AM
RE: conway's game of life - by hanscvanleeuwen - Dec-09-2016, 01:51 PM
RE: conway's game of life - by Mekire - Dec-09-2016, 02:10 PM
RE: conway's game of life - by hanscvanleeuwen - Dec-09-2016, 04:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  While loop/half-life Miraclefruit 6 8,580 Mar-06-2017, 05:24 PM
Last Post: nilamo
  conway's game of life / Single Responsibility Principle hanscvanleeuwen 13 11,319 Dec-17-2016, 08:30 AM
Last Post: hanscvanleeuwen
  Game of life using IDLE Informatics109 4 5,182 Oct-29-2016, 01:39 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020