# Basic Calculator with GUI [closed]

I recently had to add a small basic calculator to a project. I wrote a quick dirty one, but it seemed small enough to check with you people out here ;)

Just out of curiosity & an appetite to get surprised for some real hacky solutions, try and beat this one :

CODE (JS/JQUERY):

function scalcy() {
var b="", p=parseFloat,t,i;
return $("<div>").append("789/456*123-.0=+".split("").map(function(i){ return$("<button/>").text(i).width(32).height(32).click(function(){
b = (!p(i=$(this).text())? b.replace(/\D+$/,""): b) + i;
t.val(((!(i.match(/[.\d]/))? (b=eval(b.slice(0,-1))+i+"").slice(0,-1):
p(b.match(/[.\d]+/g).pop()) || 0) + "").slice(0,8));
})})).prepend(t=$("<input/>").width(123).click(function(){ this.value=b="0";})).width(130); }  Screenshot (in chrome): (DEMO) Considerations: Better the UI & lesser the bugs, the better. Minimum Functionalities: • Supports floating point arithmetic (/*-+), • Reset feature, • Continuous Operation (like working on with the last result) Note: • Use any language & library, but please not a library call like new calculator(). • Forking the above code itself is most welcome. Additional Notes: • A graphical UI is obviously considered better than not having any at all. • I'd suggest to have a look at this challenge (for inspiration): Create a GUI Piano. • What is the objective winning criteria? How do you measure how great a UI is? – Johannes Kuhn Sep 5 '13 at 8:15 • Basically the calculator should look like the calculator we all know, some buttons & a textbox (like the image above). No sacrifices to be made on that.. – loxxy Sep 5 '13 at 11:27 • I don't like to duplicate UI things (and support only the new one). I have thoose buttons on my keyboard, which don't work on your solution. – Johannes Kuhn Sep 5 '13 at 11:31 • Congratulations, you just made a chamelion question that invalidated a previously valid answer. – Johannes Kuhn Sep 5 '13 at 12:14 • @loxxy Maybe no one else attempts a question which is not well-specified and has no objective winning criterion. Reading and following the comments usually generates better questions and also more interest in solving them. – Howard Sep 5 '13 at 13:15 ## 1 Answer ## Tcl/Tk, 100 pack [entry .e -textv e] -f both -e 1 bind . <Return> {catch {expr$e} e}
bind . <Escape> {set e {}}


Buttons are not required, so leave them alone.
The GUI is great. So simple that you can finally focus on the task that you try to do.

• I'm not familiar with the language, so I need to ask: This isn't using a text-based interface, as opposed to graphical one? – shiona Sep 4 '13 at 16:02
• Tk is a graphical toolkit. Yes, it has a window and so on. Just no buttons :P – Johannes Kuhn Sep 4 '13 at 16:26
• Upvoted for strict interpretation of rules... one of my favorite games on this site. – boothby Sep 5 '13 at 1:58
• You only save 12 characters (bind <>) for in exchange for the lmap and list formating. Yes, this trade of isn't worth it most of the time. – Johannes Kuhn May 2 '18 at 0:21
• Outgolfed: 106 – sergiol May 2 '18 at 0:21