# can u help me Out? browsing

• posted
0

Hey guys, I'm new to pythonista and I need your help. I want to create a kind of calculator. I have tried it so many times, but my result has never been accepted.
In the blue circle you should specify the number.
In the yellow circle is the price of the product.
In the red circle is the "Ok" button, which calculates the number of specified products.
In the green circle then the result, so the price stand.
It would be nice if you could help me, because as a beginner I really despair of it. it would be nice if you could explain your steps.
Thank you!

• posted
0

@some-user Quick and dirty

import ui

items = {}
items['tomate'] = 2
items['salami'] = 1.5
items['käse'] = 1.5
items['butter'] = 1.5
items['frischkäse'] = 1.5

mv = ui.View()
mv.frame = (0,0,500,600)
mv.name = 'test'

d = 10
h = 32
y = d
for item in sorted(items.keys()):
p = items[item]

l = ui.Label()
l.frame = (d,y,200,h)
l.text = item

n = ui.TextField(name=item)
n.frame = (l.x+l.width+d,y,50,h)

lp = ui.Label()
lp.frame = (n.x+n.width+d,y,50,h)
lp.alignment = ui.ALIGN_RIGHT
lp.text = '{0:.2f}'.format(p) + ' €'

y = y + h + d

def b_action(sender):
t = 0
for item in items.keys():
try:
t = t + float(items[item]) * float(mv[item].text)
except:
pass
sender.superview['total'].text = '{0:.2f}'.format(t) + ' €'

b = ui.Button()
b.frame = (lp.x+lp.width+d,y,50,h)
b.border_width = 1
b.title = 'ok'
b.action = b_action

ltot = ui.Label(name='total')
ltot.frame = (d,y,100,h)
ltot.border_width = 1
ltot.alignment = ui.ALIGN_RIGHT

y = y + h + d
mv.height = y

mv.present('sheet')

• posted
0

@cvp Hey, thank you! You helped me a lot and I notice that I would not have made it without help. Maybe it is very easy for you :) but I do not really look like that yet. could you possibly explain the steps to me? But really thank you for taking the time! :)

• posted
0

n.keyboard_type = ui.KEYBOARD_NUMBER_PAD will keep the input numeric on iPhones but not on iPads.

The OK button is off the screen on an iPhone 7 unless you switch to landscape mode.

• posted
0

import ui

# init dictionnary with items names and unit proces
items = {}
items['tomate'] = 2
items['salami'] = 1.5
items['käse'] = 1.5
items['butter'] = 1.5
items['frischkäse'] = 1.5

# create main View
mv = ui.View()
mv.frame = (0,0,500,600)
mv.name = 'test'

# init some parametrized dimensions, you could change to see effect
d = 10      # horizontal and vertical distance between contiguous fields

h = 32      # height of fields
y = d           # initial y
for item in sorted(items.keys()):   # loop on items, sorted by names
p = items[item]                                 # get item price from dictionnary

# create Label for item name
l = ui.Label()
l.frame = (d,y,200,h)   # its area in main view x,y,dx,dy
l.text = item                   # init it with item name
mv.add_subview(l)           # set the label as field of main view

# create TextField for entry of number of items
n = ui.TextField(name=item)             # set its name as the item name
n.keyboard_type = ui.KEYBOARD_NUMBER_PAD    # use numeric keyboard
n.frame = (l.x+l.width+d,y,50,h)    # its area in main view

# create Label for unit price
lp = ui.Label()
lp.frame = (n.x+n.width+d,y,50,h)   # its area
lp.alignment = ui.ALIGN_RIGHT           # align the text at right
lp.text = '{0:.2f}'.format(p) + ' €'    # format the unit price as '1.23 €'

# compute vertical position y for next row
y = y + h + d

# define the code to execute when ok is tapped
def b_action(sender):
t = 0                                               # init total
for item in items.keys():       # loop on items
try:                                            # protect if number not filled or not numeric
n = float(mv[item].text)    # get entered number in textfield named item
t = t + float(items[item]) * n  # cumulate price x n
except:
pass
# fill result field with total formatted as '123.45 €'
sender.superview['total'].text = '{0:.2f}'.format(t) + ' €'

# create  button for ok
b = ui.Button()
b.frame = (lp.x+lp.width+d,y,50,h)  # its area
b.border_width = 1                                  # display a border to button
b.corner_radius = 5                                 # with rounded corners
b.title = 'ok'
b.action = b_action                                 # which code to execute of tapped

# create Label to display computed total
ltot = ui.Label(name='total')   # give a name to access it in b_action code
ltot.frame = (d,y,100,h)
ltot.border_width = 1
ltot.alignment = ui.ALIGN_RIGHT

y = y + h + d       # compute y at bottom of last total field
mv.height = y       # setof displayed main view

mv.present('sheet') # present the main view and wait

• posted
0

This post is deleted!

• posted
0

@cvp it does not work for me? which tools did you use?
I have a label for the name of the products and the price. At the input field of the number and at the result a textfield.

• posted
0

@some-user Sorry if I didn't correctly understand your post. Do you want also to enter the name of the items and their unit price?

• posted
0

@some-user Anyway, the result is a label even if it looks like a textfield due to its border

• posted
0

This post is deleted!

• posted
0

@cvp The specified products are entered with a number. And then come out together bottom left. for example
Tomate 4 (2 €)
Käse 4 (1.50 €)
Salami 0 (1.50 €)
Butter 0 (1.20 €)
Frischkäse 3 (1.50 €)

Is there product in a label? Or which tool would be used in the case?
After the product comes the number you should enter. Is that then a text field in the case? You have to enter a number. And behind is the price. Which tool do you use for this? Then press the "Ok" button, which is on the bottom right. The ok button calculates the whole thing and the result then appears on the lower left, in a field. In my example, the result would be, so the total price would be 18.50 €. That number would pop up, anyway. So that was just one example, the whole in the sketch I sent as a Twitter link. Thanks for your helpfulness :) I'm sorry, but I'm not checking it yet.

• posted
0

@some-user Sorry, but I leave today and not sure when I could answer...

• posted
0

@some-user Still one question: did you try my little script?
And you ask "which tool" but do you use the Pythonista app on iPhone/iPad or do you have an Android device like in your twitter image?
Here is a Pythonista forum, thus my question is obviously stupid.

• posted
0

This post is deleted!

• posted
0

@cvp Of course, I tried your script, but it did not work. So I thought I've made my ui wrong. That's why the question with the tools. I work with Pythonista on my iPad, but this is what I'm doing right now on my phone. I only work with my iPad and have no social media on it. Take your time. I think it's very friendly and not a matter of course that you help me and I'm really grateful.

• posted
0

You might get better help if you post your code and UI, and explain what your problem is.

To post a UI, you can tap the Edit button, in the library menu, select the pyui file and py file, then tap the share button, and then share to gist.

• posted
0

@some-user As my little dirty script works on my iPad, could you explain what doesn't work for you. Problem of screen dimensions? Error message?

• posted
0

@cvp So there is no error message with me. It turns up without any message. I enter the numbers and press the Ok button. But nothing happened. So I assumed that I have mis-designed my UI. Could you show me how you designed yours?

• posted
0

@some-user I can't show more than the script, all is included in it, without any external design, that's why I don't understand your question, I'm sincerely sorry.

Do you use my script without changing it?
If you run it on your iPad, do you also have troubles?

• posted
0

@some-user Perhaps I did not understand your post.
If you have your own script and your own UI design, and your script does not work as expected, in this case, as adviced by @JonB , post here your script and your .pyui file.
For this last one, you can share it as gist or rename the file as .txt, edit it, select all, copy and paste here in a post.

• posted
0

@cvp sorry for the poor quality, but i had to go fast. So that's my script.pyui. It has a size of 600 x 600. My background is a custom view. I've always used labels in the red circles. In the blue circle I have used text fields so that there can be entered the number of products sold. In the yellow circle is the button that you click after entering the numbers. He calculates it and the result appears in the green circle, which is also a label.
Because it's wrong with me, I thought, I made it wrong. For example, to replace a text field with a label. That's why I asked you. I just copied out the code and used it. If I press Play then this picture appears exactly what you see in my Twitter link. I can enter numbers in the text field, but if I press the button nothing happens.