-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.py
116 lines (78 loc) · 2.03 KB
/
calculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- coding: utf-8 -*-
import pygtk;
pygtk.require( '2.0' );
import gtk;
# ... #
def delete( widget, data ):
return False;
def des( widget, data = None ):
gtk.main_quit();
def doMath( widget, data = None ):
global result_label, first_number, second_number, operation;
operand1 = first_number.get_text();
operand2 = second_number.get_text();
op = operation.get_text();
if ( not operand1 or not operand2 or not op ):
result_label.set_text( "يرجى تعبئة المعلومات المطلوبه" );
else:
operand1 = int( operand1 );
operand2 = int( operand2 );
result = operand1;
if op == "+":
result += operand2;
elif op == "-":
result -= operand2;
elif op == "*":
result *= operand2;
elif op == "/":
result /= operand2;
else:
result_label.set_text( "العمليه التي قمت بإختيارها غير صحيحه" );
return False;
result_label.set_text( str( result ) );
def keyEvent( widget, data ):
key = gtk.gdk.keyval_name( data.keyval );
if ( key == 'Return' ):
doMath( None );
# ... #
win = gtk.Window();
win.set_title( "آله حاسبه" );
win.connect( 'delete_event', delete );
win.connect( 'destroy', des );
# ... #
main_box = gtk.VBox();
win.add( main_box );
# ... #
box1 = gtk.HBox();
# ... #
first_number = gtk.Entry();
box1.pack_start( first_number );
first_number.show();
# ... #
operation = gtk.Entry();
box1.pack_start( operation );
operation.show();
# ... #
second_number = gtk.Entry();
box1.pack_start( second_number );
second_number.show();
# ... #
first_number.connect( 'key_release_event', keyEvent );
operation.connect( 'key_release_event', keyEvent );
second_number.connect( 'key_release_event', keyEvent );
# ... #
main_box.pack_start( box1 );
box1.show();
# ... #
button = gtk.Button( "أظهر الناتج" );
button.connect( 'clicked', doMath );
main_box.pack_start( button );
button.show();
# ... #
result_label = gtk.Label();
main_box.pack_start( result_label );
result_label.show();
# ... #
main_box.show();
win.show();
gtk.main();