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
Medium Priority
2,989 Views
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
Question by:liamrichards
1 Comment

LVL 39

Accepted Solution

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

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 …
###### Suggested Courses
Course of the Month12 days, 2 hours left to enroll