Alternative to using ButtonBar in SageMath (interact)
Hello everyone,
I'm currently trying my hand at an interactive calculator, coding it in Sagemath. I quickly got a good result for the keypad using ButtonBar
:
eingabe = " "
@interact
def tasten(z = ButtonBar(
["(", ")", ".", "+",
"1", "2", "3", "-",
"4", "5", "6", "*",
"7", "8", "9", "/",
"=", "0", "⟳", "←" ],
ncols=4, width="4em", label=" ")):
global eingabe
if z == "⟳":
eingabe = " "
elif z == "←":
eingabe = eingabe[:-1]
elif z == "=":
ergebnis = sage_eval(eingabe)
eingabe += z
eingabe += str(ergebnis)
else:
eingabe += z
print("Rechnung:", eingabe)
Unfortunately, ButtonBar only works in SageCell Server, but not in Jupyter Notebook with Sage 9.5.
I have researched the topic in various forums and usually selector
(with the option buttons=True) is mentioned as an alternative to ButtonBar
. However, since selector is about choosing something from various options, it is not intended that a same button is pressed twice. For my calculator this means that the buttons do not react several times in succession and therefore no numbers with the same digits can be entered (e.g. 11, 22, etc):
eingabe = " "
@interact
def tasten(z = selector(
["(", ")", ".", "+",
"1", "2", "3", "-",
"4", "5", "6", "*",
"7", "8", "9", "/",
"=", "0", "⟳", "←" ],
ncols=4, width="4em", label=" ",buttons=True, default = "0")):
global eingabe
if z == "⟳":
eingabe = " "
elif z == "←":
eingabe = eingabe[:-1]
elif z == "=":
ergebnis = sage_eval(eingabe)
eingabe += z
eingabe += str(ergebnis)
else:
eingabe += z
print("Rechnung:", eingabe)
Does anyone have any idea how I can get the same functionality as in the above example with ButtonBar, but with a code that also works in my Jupyter Notebook?
Thank you in advance!
Sage 9.5 is pretty old by now. Can't you install Sage 10.6 on your computer?
I think that's basically a good idea. But it probably won't help me with the problem mentioned above either...