Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Textfield with ui
-
I have here a programm which can find out all prime numbers. But I have the Problem, that I only can print the result in the console. I write
tf.text = Right
but it don‘t works why? I get a error withstr
andint
. But I don‘t know how to fix that.import ui dialog = ui.View() tf = ui.TextField() tf.name = 'Test' tf.frame = (50,50,1000,100) tf.keyboard_type = ui.KEYBOARD_DECIMAL_PAD tf.text = '' tf.placeholder = 'Gib was ein!' def primzahl(): p = int(tf.text) i = 2 istPrimzahl = True teiler = 0 while (i < p): if p % i == 0: istPrimzahl = False teiler = i break i += 1 if istPrimzahl: tf.text = 'Die Zahl', p , 'ist eine Primzahl.' else: print ("Die Zahl",p, "ist keine Primzahl, weil sie durch " , i , " teilbar ist.") def tf_action(sender): primzahl() tf.action = tf_action dialog.add_subview(tf) ebutton = ui.Button() ebutton.title = '=' ebutton.frame = (50,200,1000,100) ebutton.background_color = "red" def ebutton_action(sender): tf.text = "gedrückt!" ebutton.action = ebutton_action menubutton = ui.ButtonItem() menubutton.title = 'fghjk' dialog.right_button_items = [menubutton] dialog.add_subview(ebutton) dialog.present('fullscreen') tf.begin_editing() #sheet
-
@Python567 try already with
tf.text = 'Die Zahl ' + str(p) + ' ist eine Primzahl.'
-
No, thanks:)
-
-
@cvp Sorry, I wanna write a first something else wich beginn with „no“. 😐
-
@Python567 no problem 😉
-
F-strings (
tf.text = f'Die Zahl {p} ist eine Primzahl.'
) are a single instruction in Python bytecode.
This makes them faster and more efficient than legacy string formatting https://www.scivision.dev/python-f-string-speed
Improved readability is also a clear value. -
@cvp that code works cool but what if I want to use it without presenting, the keyboard shortcuts?
-
-
OK. Thanks!