def init(self): cb1 = awt.Checkbox('Checkbox 1') cb2 = awt.Checkbox('Checkbox 2') cb3 = awt.Checkbox('Checkbox 3', state=1) p1 = awt.Panel(layout=awt.FlowLayout()) p1.add(cb1) p1.add(cb2) p1.add(cb3) cbg = awt.CheckboxGroup() cb4 = awt.Checkbox('Checkbox 4', cbg, 0) cb5 = awt.Checkbox('Checkbox 5', cbg, 0) cb6 = awt.Checkbox('Checkbox 6', cbg, 0) p2 = awt.Panel(layout=awt.FlowLayout()) p2.add(cb4) p2.add(cb5) p2.add(cb6) self.setLayout(awt.GridLayout(0, 2)) self.add(p1) self.add(p2) self.validate()
def doMath(e): n1 = getField(f1) n2 = getField(f2) sum.setText(repr(n1 + n2)) diff.setText(repr(n1 - n2)) prod.setText(repr(n1 * n2)) quo.setText(repr(n1 / n2)) f = awt.Frame('BSH Calculator (jpython)', windowClosing=exit) f1 = awt.TextField(20, actionPerformed=doMath) f2 = awt.TextField(20, textValueChanged=doMath) p = awt.Panel() p.setLayout(awt.GridLayout(2, 2)) p.add(awt.Label('Enter Operand')) p.add(f1) p.add(awt.Label('Enter Operand')) p.add(f2) f.add('North', p) f.add("Center", awt.Label('Results:')) p = awt.Panel() p.setLayout(awt.GridLayout(4, 2)) p.add(awt.Label('Sum')) sum = awt.TextField(20) p.add(sum)
g.drawString("Invalid Expression", x, y) def setExpression(self, e): "@sig public void setExpression(java.lang.String e)" try: self.function = eval('lambda x: ' + e) except: self.function = None self.repaint() if __name__ == '__main__': def enter(e): graph.setExpression(expression.text) expression.caretPosition = 0 expression.selectAll() p = awt.Panel(layout=awt.BorderLayout()) graph = Graph() p.add(graph, 'Center') expression = awt.TextField(text='(sin(3*x)+cos(x))/2', actionPerformed=enter) p.add(expression, 'South') import pawt pawt.test(p, size=(300, 300)) enter(None)