write a code for undo button(GUI) in Sudoku

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • starish
    New Member
    • May 2010
    • 2

    write a code for undo button(GUI) in Sudoku

    Hello ...

    I have given code for undo in Sudoku which is:

    def get_entry(self, r, c):
    """Get the entry at row r and column c

    get_entry(int, int) -> char
    """

    return self._game[r][c]

    def set_entry(self, r, c, v):
    """Set the entry at row r and column c to v

    set_entry(int, int, char) -> void
    """

    self._game[r][c] = v
    entries = [(r,c)]
    if self._do_auto_f ill:
    auto = self.auto_fill( )
    entries.extend( auto)
    self._undo_stac k.append(entrie s)

    def undo(self):
    """Undo the last move."""
    if self._undo_stac k != []:
    entries = self._undo_stac k.pop()
    for r,c in entries:
    self._game[r][c] = ' '

    Then I have been asked define class for a widget that contains button for undoing last move in Sudoku.. This what I have written:

    class Commands(Frame) :
    def __init__(self, parent):
    Frame.__init__( self, parent)

    self.button1 = Button(self, text="Undo", width=12, command=self.pr essed)
    self.button1.pa ck()

    def pressed(self):
    print "Button pressed..."

    However, I don't know how to call the function undo to link with this Undo button in GUI..

    I hope you can help me to sort this problem.
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    Hi.

    It's a little difficult to engage on this, because you haven't put the code tags in. It's hard to read, esp Python, because the indentation is important.

    You could try to change this line:
    Code:
    self.button1 = Button(self, text="Undo", width=12, command=self.pressed)
    to this:

    Code:
    self.button1 = Button(self, text="Undo", width=12, command=undo)
    Or call it from the "pressed" function.

    Comment

    Working...