Forum Archive

String return with dialogs

Tito

Hi, i´m working on a more visual version of a little script for helping me in my job.

The initial script was a simple console thing with prints and prompts formatted in the end.

Now I would like to make it a bit visual importing the dialogs module.

The documentation, after showing the function says: The edited text is returned as a string (if the dialog is cancelled, None is returned instead), and I’m unable to use the text, it disappears just with the prompt.

Here is part of the code, I hope somebody could give me a hand.

from sys import argv
import dialogs, string

dialogs.text_dialog(title='¿Quién es la persona destinataria de la oferta?')

Thanks a lot...

dgelessus

In general, you can use dialogs.text_dialog like the standard input function: you give the function a string that is shown to the user, and the text typed by the user is returned. So if your original script looks like this for example:

name = input("What is your name? ")
print("Hello " + name)

You can replace input with dialogs.text_dialog and it will work the same, but it will use a text dialog instead of the console:

import dialogs
name = dialogs.text_dialog("What is your name?")
print("Hello " + name)

You can also show the response in an alert (instead of the console) using dialogs.alert instead of print.

enceladus

Here is a simple dialog template that uses a pyui file created using designer. This helps to use ui controls like images, textviews, segmentedcontrol in dialogs. The gist with sample pyui file is here. I hope it helps

https://gist.github.com/73431fef1f00c462c3bee0551bd14be8

It is previously posted here.

https://forum.omz-software.com/topic/4507/form-dialogs-add-segmented-control-type/7

Tito

@dgelessus it works, many thanks. :)

Tito

@enceladus hi, I’m overwhelmed for your script, I think right now is out of my capabilities, I’m just a learner and got a lot of obstacles in my way, I thought could learn Python trough Pythonista from scratch and couldn’t be more wrong.

I hope someday could give a use to your great code and tell you.

Thanks.