[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
text.set("ERROR") # bad as statement too? else: text.set('') # worked as a statement except: text.set("ERROR") # other eval expr ...
In CalcGui’s constructor, buttons are coded as lists of strings; each string represents a row and each character in the string r ...
eval Parses, evaluates, and returns the result of a Python expression represented as a string. exec Runs an arbitrary Python sta ...
Inner().mainloop() It can also be embedded in a container class—Example 19-19 attaches the simple cal- culator’s widget package, ...
PyCalc—A “Real” Calculator GUI Of course, real calculators don’t usually work by building up expression strings and evaluating t ...
Figure 19-4. PyCalc calculator at work on Windows 7 If you do run this, you’ll notice that PyCalc implements a normal calculator ...
dictionary is thrown up in the main window for use in larger expressions. You can use this as an escape mechanism to employ exte ...
sends operators and operands entered in the GUI to an embedded instance of the Evaluator class. The Evaluator class Manages two ...
onto operators, and continue scanning user inputs. When “eval” is pressed at the end, 4 is pushed onto operands, and the final ...
parenthesized subexpression is popped and evaluated ((3 4), then (1 + 12)), and 13 is displayed in the entry field. On pressing ...
Operands and temporary results are always stacked as strings, and each operator is applied by calling eval. When an error occurs ...
-apply font to input field to make it larger; -use justify=right for input field so it displays on right, not left; -add 'E+' an ...
self.entry = entry(self, TOP, self.text) # font, color configurable self.entry.config(font=font) # 3.0: make display larger self ...
self.erase = 0 def onOperator(self, char): self.eval.shiftOpnd(self.text.get()) # push opnd on left self.eval.shiftOptr(char) # ...
elif pressed == '?': self.help() def onHist(self): show recent calcs log popup from tkinter.scrolledtext import ScrolledText # o ...
return value # or x.pop(), or del x[-1] def topOpnd(self): return self.opnd[-1] # top operand (end of list) def open(self): self ...
exec(code, self.names, self.names) # try stmt: None self.hist.append(code) result = None return result def getHist(self): return ...
if name == 'main': import sys if len(sys.argv) == 1: # % calculator_test.py root = Tk() # run 3 calcs in same process CalcGui(To ...
The two extensions in this script are artificial, of course—they simply add labels at the top and bottom of the window—but the c ...
def onPi(self): self.calc.text.set(self.calc.eval.runstring('pi')) if name == 'main': root = Tk() button(root, TOP, 'Quit', root ...
«
71
72
73
74
75
76
77
78
79
80
»
Free download pdf