Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Making a GUI Calculator in Python with Tkinter

Posted on 2009-02-21
1
Medium Priority
?
2,989 Views
Last Modified: 2012-05-06
Hi,
i'm just starting out with python today, and am trying to make a basic calculator program in Python with the Tkinter gui module.

At the moment I have the buttons 1-9  and each one calls a separate function, i.e. OnButtonClick1, OnButtonClick2, etc.

However since they all basically do the same thing, and only the number is different, there must me an easier way to do this?
Is there any way that I can just have one function such as OnButtonClick which can determine which button was pressed and do its logic based on that?

Thanks,
0
Comment
Question by:liamrichards
1 Comment
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 2000 total points
ID: 23701058
You can have the same method handling all button clicks.

Take a look at this example for inspiration:

http://www.daniweb.com/code/snippet610.html
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question