-apply font to input field to make it larger;
-use justify=right for input field so it displays on right, not left;
-add 'E+' and 'E-' buttons (and 'E' keypress) for float exponents;
'E' keypress must generally be followed digits, not + or - optr key;
-remove 'L' button (but still allow 'L' keypress): superfluous now,
because Python auto converts up if too big ('L' forced this in past);
-use smaller font size overall;
-auto scroll to the end in the history window
to do: add a commas-insertion mode (see str.format and LP4E example);
allow '**' as an operator key; allow '+' and 'J' inputs for complex
Numbers; use new decimal type for fixed precision floats; as is, can
use 'cmd' popup windows to input and evaluate things like complex, but
can't be input via main window; caveat: PyCalc's precision, accuracy,
and some of its behaviour, is currently bound by result of str() call;
################################################################################
"""
from tkinter import * # widgets, consts
from PP4E.Gui.Tools.guimixin import GuiMixin # quit method
from PP4E.Gui.Tools.widgets import label, entry, button, frame # widget builders
Fg, Bg, Font = 'black', 'skyblue', ('courier', 14, 'bold') # default config
debugme = True
def trace(*args):
if debugme: print(args)
################################################################################
the main class - handles user interface;
an extended Frame, on new Toplevel, or embedded in another container widget
################################################################################
class CalcGui(GuiMixin, Frame):
Operators = "+-*/=" # button lists
Operands = ["abcd", "0123", "4567", "89()"] # customizable
def init(self, parent=None, fg=Fg, bg=Bg, font=Font):
Frame.init(self, parent)
self.pack(expand=YES, fill=BOTH) # all parts expandable
self.eval = Evaluator() # embed a stack handler
self.text = StringVar() # make a linked variable
self.text.set("0")
self.erase = 1 # clear "0" text next
self.makeWidgets(fg, bg, font) # build the GUI itself
if not parent or not isinstance(parent, Frame):
self.master.title('PyCalc 3.0') # title iff owns window
self.master.iconname("PyCalc") # ditto for key bindings
self.master.bind('
self.entry.config(state='readonly') # 3.0: not 'disabled'=grey
else:
self.entry.config(state='normal')
self.entry.focus()
def makeWidgets(self, fg, bg, font): # 7 frames plus text-entry
1470 | Chapter 19: Text and Language