# Please Help: Currency Converter

**URL:** <https://discourse.processing.org/t/please-help-currency-converter/30250>\
**Category:** Processing.py\
**Tags:** homework\
**Created:** [May 24, 2021, 3:09pm UTC](https://discourse.processing.org/t/please-help-currency-converter/30250 "2021-05-24T15:09:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bridgette](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bridgette](https://discourse.processing.org/u/bridgette)\
**Post date:** [May 24, 2021, 3:09pm UTC](https://discourse.processing.org/t/please-help-currency-converter/30250/1 "2021-05-24T15:09:36Z")

</div>

Hello!

I have an assignment coming up where I have to create a currency converter using python, but I’m really confused on where or how to begin. Does anyone have any tips on how I could start? Like how would I make a simple window that displays two different currency slots? Any help is much appreciated, thank you!

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [May 24, 2021, 4:06pm UTC](https://discourse.processing.org/t/please-help-currency-converter/30250/2 "2021-05-24T16:06:29Z")

</div>

Hello @bridgette

A good place to start is by writing out in **pseudocode** the steps that need to happen in order to solve the problem. At this stage you don’t need to know all of the syntax or algorithms to complete the task. You’re just outlining the logic or a roadmap that you are going to follow. Pseudocode will also help to clarify the particular area or areas of your question on how to create a currency converter.

\*\*\* Please take note, that since this is a homework question (and forum rules), we can supply guidance but not code solutions. I do not think you are asking for a solution but just want to explain why I have given more of a guidance answer.

By the way, I did a very quick search on YouTube, and there are several tutorials there that can get you started as well. 🙂

🤓

---

<div class="post-metadata">

**Author:** ![bridgette](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bridgette](https://discourse.processing.org/u/bridgette)\
**Post date:** [May 24, 2021, 4:10pm UTC](https://discourse.processing.org/t/please-help-currency-converter/30250/3 "2021-05-24T16:10:36Z")

</div>

Hi!

Thank you so much for replying. Yup, so at the beginning when I was doing research, I could only find tutorials and coding using Tkinter, but because I’ve never learnt how to use imported libraries (and I’m not even sure I’m allowed to use it for this assignment) I resorted to asking everyone here. What exactly is pseudocode?

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [May 24, 2021, 4:14pm UTC](https://discourse.processing.org/t/please-help-currency-converter/30250/4 "2021-05-24T16:14:56Z")

</div>

Pseudocode examples here:  
[https://www.unf.edu/~broggio/cop2221/2221pseu.htm](https://www.unf.edu/~broggio/cop2221/2221pseu.htm)

Search engines are great for this type of question btw. 🙂

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [May 24, 2021, 4:56pm UTC](https://discourse.processing.org/t/please-help-currency-converter/30250/5 "2021-05-24T16:56:29Z")

</div>

> [@bridgette](#):
>
> (and I’m not even sure I’m allowed to use it for this assignment)

Perhaps you could ask your instructor whether you’re allowed to use Tkinter for the project? 🙂

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [May 24, 2021, 9:26pm UTC](https://discourse.processing.org/t/please-help-currency-converter/30250/6 "2021-05-24T21:26:17Z")

</div>

Converting one currency to another is the easy part – it’s just a multiplication operation. Building the graphic interface is the challenging bit.

To begin, consider: how does the user enter the currency values? Type numbers into a text input field? Press calculator-like buttons? …

Tkinter won’t work in Processing, but there are libraries like ControlP5 you can use instead.

---

<div class="post-metadata">

**Author:** ![bridgette](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bridgette](https://discourse.processing.org/u/bridgette)\
**Post date:** [May 24, 2021, 9:33pm UTC](https://discourse.processing.org/t/please-help-currency-converter/30250/7 "2021-05-24T21:33:04Z")

</div>

Yes, that’s basically how I was planning on doing it. Essentially, I wanted to have a window that has all the components of a currency converter

 ![Screen Shot 2021-05-25 at 01.30.46](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/32f6584aa769c9fb38bfad3d0fc8591518586439.png)  
^^ To basically look like that  
My assignment is meant to be creative and it’s not meant to be based on real currencies. So, not a lot of maths would be involved. But I’m just really stuck on creating the actual window itself. I tried using `def setup` and `def draw` functions but I’m still stuck

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [May 24, 2021, 9:57pm UTC](https://discourse.processing.org/t/please-help-currency-converter/30250/8 "2021-05-24T21:57:19Z")

</div>

I’m not sure what you mean by “window” – Processing spawns a display window every time you run the code?

The way I see it, you need four Processing functions to make this work: `setup()` and `draw()` to structure the sketch; and `mouseClicked()` and `keyPressed()` to capture mouse and keyboard input. What follows is a basic scaffold.

The `setup()` and `draw()` look like this (I’m just drawing the input field here):

```python
amount = '' # text you see in the input field
fieldstroke = '#000000' # stroke color for the input field
result = 0

def setup():
    size(500, 500)
    textSize(25)
    strokeWeight(3)

def draw():
    background('#999999')
    
    # draw text input field
    fill('#FFFFFF')
    stroke(fieldstroke)
    rect(40, 60, 150, 50)
    fill(0)
    text(amount, 55, 95)
    
    '''
    # draw result button
    fill('#0000FF')
    ...

```

The variables (`amount`, `fieldstroke`, `result`) control the ‘app’ state. The `mouseClicked()` function interacts with those variables to affect the state:

```python
def mouseClicked():
    global fieldstroke, result
    
    # select input field when it's clicked
    if (mouseX > 40 and mouseX < 40+150 and 
        mouseY > 60 and mouseY < 60+50):
        fieldstroke = '#FF0000'
        
    '''
    # result (blue button) code
    if (mouseX > 200 and mouseX < 200+50 and 
        mouseY > 60 and mouseY < 60+50):
        ...

```

Now, for the `keyPressed()` section. If the field stroke is red, you can type text into it (by affecting the `amount` variable):

```python
def keyPressed():
    global amount
    
    # if the input field has a red stroke, change the amount
    if fieldstroke == '#FF0000':
        amount += key

```

That should be enough to get you heading in the right direction.

---

<div class="post-metadata">

**Author:** ![bridgette](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bridgette](https://discourse.processing.org/u/bridgette)\
**Post date:** [May 24, 2021, 10:07pm UTC](https://discourse.processing.org/t/please-help-currency-converter/30250/9 "2021-05-24T22:07:25Z")

</div>

Thank you so much! this really helps

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 27, 2021, 11:25am UTC](https://discourse.processing.org/t/please-help-currency-converter/30250/10 "2021-05-27T11:25:25Z")

</div>

@bridgette

There are also examples to explore that come with the Processing software.

Add Python Mode, start a new sketch in Python mode and then go to menu and open:  
_File \> Examples… \>_

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/95b9cfadb91a00693f3c942f3c852a6ea9a105ab.png)

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/19eb0df61b9702c39f8dfe1f346b2041207e763d.png)

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/657a2b71f59f00915184c52568b8c85d0e2c5f0a.png)

`:)`
