Trebuchet Calculator Program In Python

Python Program to Make Calculator - here you will learn how to make a simple calculator to perform basic mathematical operation such as add subtract multiply and. GUI Scientific Calculator Homework. Sounds In Python TKinter Program: 'Focus' Control Between External Program - 3 replies; Python Tkinter Calculator Help!
Hello, it is me once more. I am using Python 2.3, and I must use Zelle's graphics class (and I must agree with many of you. Tkinter is much better). We have been tasked with creating a Graphical Scientific Calculator. M+ is adding display to the memory MR is recalling the memory. Ie: You do a sum and get the result 6.3322 and you need this for another sum. So, you press M+ to ad 6.3322 to the memory, then you type in the next sum.
When you need 6.3322, you press the MR button, which insterts the current value of the memory (6.3322 in this case) into the display. MC is obviously deleteing the contents of the memory (set to 0?). I'm not sure about the difference between M+ and MS though. Try looking at the system calculator.hope this helps! Edited 7 Years Ago by SgtMe: n/a. Thank you for that clarification. Essentially, pressing MS makes the value of memory become the current display?
Pressing M+ adds the value of the current display to memory? MR returns the current value of memory? And MC sets the value of memory to 0? Update for the above code: def __createButtons(self): # create list of buttons # start with all the standard sized buttons # bSpecs gives center coords and label of buttons bSpecs = [(2.5,1,'0'), (4,1,'.' ), (1,2.5,'1'), (2.5,2.5,'2'), (4,2.5,'3'), (5.5,2.5,'+'), (7,2.5,'-'), (1,4,'4'), (2.5,4,'5'), (4,4,'6'), (5.5,4,'*'), (7,4,'/'), (1,5.5,'7'), (2.5,5.5,'8'), (4,5.5,'9'), (5.5,5.5,'. OK, I think I have found a design that is 'visually appealing'.
I will work on implementing the layout later. Right now, I am having difficulties figuring out how to implement the the functions of the sin, cos, etc. In the case of sin, cos, and tan, I am getting error messages that the math class does not exist. So, I have taken those out for now. MR, MS, MC, and M+ are also giving me trouble, but right now, I think it is just because I am drawing a blank on how to deal with memory.
I will worry about them later, as the more pressing matter is getting the functions to properly process everything. I am able to process everything else, but I can only get the display to read 'ERROR'. This is good for when trying to find the reciprocal of 0, square root of a negative, log of a negative, ln of a negative, or e to a large power. The following is the code that I have so far. It only includes what I have changed from what I have posted above. I see no point in reposting the entire thing over and over again. Def processButton(self, key): '' elif key == 'MS': self.memory == eval(text) elif key == 'M+': self.memory += eval(text) elif key == 'MR': self.display.setText(text+str(self. Ruse Keygen Software. memory)) elif key == 'MC': self.memory == 0'' # Updates the display of the calculator for press of this key text = self.display.getText() if key == 'C': self.display.setText(') elif key == '.
My apologies for not including the button class. Here it is: # button.py # A simple Button widget. From graphics import * class Button: ''A button is a labeled rectangle in a window. It is activated or deactivated with the activate() and deactivate() methods. The clicked(p) method returns true if the button is active and p is inside it.' ' def __init__(self, win, center, width, height, label): '' Creates a rectangular button, eg: qb = Button(myWin, Point(30,25), 20, 10, 'Quit') '' w,h = width/2.0, height/2.0 x,y = center.getX(), center.getY() self.xmax, self.xmin = x+w, x-w self.ymax, self.ymin = y+h, y-h p1 = Point(self.xmin, self.ymin) p2 = Point(self.xmax, self.ymax) self.rect = Rectangle(p1,p2) self.rect.setFill('lightgray') self.rect.draw(win) self.label = Text(center, label) self.label.draw(win) self.deactivate() def clicked(self, p): 'Returns true if button active and p is inside' return self.active and self.xmin. Here is my entire code to date.
For whatever reason, the only value I can get for MC or M+ is 0. No matter what. I have tried a couple of different methods to initialize memory, but I only get 0 or an error message in python saying that Memory or Result is referenced before assignment. I have contacted my professor regarding this, but he has been, like before, less than helpful. He spoke about the calculator looking ugly and how I must only import the math functions I use, instead of explaining to me what I am doing wrong concerning memory.
I understand that the calculator does not look pretty, but my focus right now is to have the calculator work, not have it look pretty. We are not required to force floating point values. We are using Python calculations. If Python says that 7/3 = 2, then it is true. My professor says that this is to make this easier on us and not have to deal with String formatting. Once I have the memory part done, I can begin working on the memory in use light. From graphics import * from button import Button import math class Calculator: # This class implements a simple calculator GUI def __init__(self): # create the window for the calculator win = GraphWin('calculator') win.setCoords(0,0,9,13.5) #from (0,0,6,7) win.setBackground('slategray') self.win = win # Now create the widgets self.__createButtons() self.__createDisplay() self.memory = 0 def __createButtons(self): # create list of buttons # start with all the standard sized buttons # bSpecs gives center coords and label of buttons bSpecs = [(2.5,1,'0'), (4,1,'.'
), (1,2.5,'1'), (2.5,2.5,'2'), (4,2.5,'3'), (5.5,2.5,'+'), (7,2.5,'-'), (1,4,'4'), (2.5,4,'5'), (4,4,'6'), (5.5,4,'*'), (7,4,'/'), (1,5.5,'7'), (2.5,5.5,'8'), (4,5.5,'9'), (5.5,5.5,'. OK, let's help you little with the memory. There is bug in pi part, it adds * when there is zero on screen, should replace the screen text with value of pi, easy to fix. Also first C (or 0) and MS does not clear the M indicator, even it does same as MC. BTW if you add if innumber: text=text+'.' ## use float value allways at beginning of handling the '=', the calculator does right the 1/3=0.3333333 Next job I left for you is to make sin etc to set the result flag, so entering number after them will clear the screen automatically. With this implementation, you can not count for example sin(1+45/23) directly only 1+45/23=sin.
This program also crashes if you do C. Thank you, tonyjv, that has helped me out a lot. Strangely, though, I came up with a very similar solution to my Memory problem during my morning commute. All I needed for a memory indicator was a 'light' that turned red while in use, and was dark while not in use. Sameeksha Informatica Code Review Tool.
All that is really left for me right now is properly importing the math class (I can only import what I use), figuring out how to fix pi, and organizing the layout of the calculator. I'll mull over it throughout the rest of the day and I should have a nice solution by the time I get home. Again, tonyjv, thank you for your help. It really did clear a lot of things up for me. Maybe must try to do it in less than 100;-) Tony I tried it with Tkinter, but I did not want to take out all empty lines etc.
So it is not under 100 lines. It does have arcusfunction and hyperfunctions. You can also use scientific notation e.g. You can type anything from keyboard, so this is little unsafe. (unprotected eval) Here could include the number checking routine I posted resently, but it would need to expand to take acount for the allowed functions. Memory and hyp indicator not implemented.
Put included keyboard images to same directory with the code. From Tkinter import * from math import * from random import random hyps=arc=' mem=0 resflag=False ## for clearing the display after result automatically without CE fact=factorial def calc(s): global resflag brackc = display.get().count('(') - display.get().count(')') try: display.set(eval('1.0*'+display.get()+')'*brackc)) ## try to fix bracket unbalance except: display.set('Error') number.icursor('end') resflag=True def push_key(e): global resflag if 38',calc) number.bind(',clear) root.bind(',push_key) root.mainloop() Edited 7 Years Ago by pyTony: n/a. Another fix for resetting number after result so here is the hole function again: def push_key(e): global resflag if 38.