473,378 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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_fill:
auto = self.auto_fill()
entries.extend(auto)
self._undo_stack.append(entries)

def undo(self):
"""Undo the last move."""
if self._undo_stack != []:
entries = self._undo_stack.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.pressed)
self.button1.pack()

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.
May 17 '10 #1
1 2786
Glenton
391 Expert 256MB
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:
Expand|Select|Wrap|Line Numbers
  1. self.button1 = Button(self, text="Undo", width=12, command=self.pressed)
to this:

Expand|Select|Wrap|Line Numbers
  1. self.button1 = Button(self, text="Undo", width=12, command=undo)
Or call it from the "pressed" function.
May 17 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: ulysses | last post by:
Hi,all I use wxPython make a bittorrent client. I find wxPython very slow and use many many memory. When app start, it need 19MB memory. I only use common GUI components. Python is a really...
33
by: Nick Evans | last post by:
Hello there, I have been on and off learning to code (with python being the second language I have worked on after a bit of BASIC). What I really want to know is, if you are going to actually...
38
by: rzed | last post by:
Periodically, we see questions about which gui package is best, or which database package to use. These questions typically trigger some exchanges of opinion, though of course this no one best...
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
1
by: LenS | last post by:
If this is the wrong place to post this, please advise better place. Otherwise, I have created the following python program and it works. Running on XP. I think I am now at that stage of learning...
8
by: John | last post by:
This is a simple, newbe question. In Asp/VB there are 2 ways to display message on page load I can double click on aspx page and aspx.vb file is created: Private Sub Page_Load(ByVal sender As...
1
by: holysmokes99 | last post by:
I am trying to implement a cancel button on my application that ingests a bunch of data from a text file into a database. I have not worked too much with threads, so I am having some trouble. I had...
5
by: Ryan Ginstrom | last post by:
Apropos recent threads about GUI editors, coming from a Win32/WTL C++ background, I actually like the idea of being able to (easily) create GUIs programmatically. But I still see a lot of the...
1
by: Kburge03 | last post by:
Hi!! I've been working on this assingment for class where I have to design and implement an application that displays two Die objects, a button, and a label. Every time the button is pushed, the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.