Forum: Poser Python Scripting


Subject: is there any simple user input function available ??

jenay opened this issue on Jun 17, 2008 · 5 posts


jenay posted Tue, 17 June 2008 at 4:54 AM

I need some help with Python from the gurus here :)
I am just a beginner with Python.
here is a code snippet:

ok = "y"
while ok !="x":
        ok = raw_input("... repeat action ...")
        print("... do something ...")
print ("... quit ...")

I wrote a simple loop that exits when the "x" is entered. It works fine within
my Python console, but PoserPython refuses to accept the input (raw_input) funktion.
now I didn't find any docu about this matter. seems, that the PoserPython console
doesn't accept any user input ??
do I have to use Tk for that purpose and create a dialog along with buttons - or is
there a simpler solution ???
I found somethong like Poser.dialog - but this seems not available under Poser5 ??


PhilC posted Tue, 17 June 2008 at 5:09 AM

In Poser 6 and later, Poser has a number of input dialogs but for Poser 5 your only option is to use Tkinter. Raw input does not work in any version.


jenay posted Tue, 17 June 2008 at 5:42 AM

Hi Phil - thanks for the quick answer :)
so it seems that I have to learn TkInter ...


adp001 posted Tue, 17 June 2008 at 7:00 AM

To use Tkinter isn't bad. Try this for a fist start to solve your problem:

from Tkinter import * import tkMessageBox

if tkMessageBox.askyesno(title="My Questiondialog", 
                         message="Please press Yes or No") :
    # YES-Button pressed - we are happy :)
    print "Thanks, you pressed YES"

else :
    # NO-Button pressed or dialog closed
    print "Thanks, you decided to press NO"

Because this simple demo doesn't use a "complete" Tkinter environment, Tkinter sets one up for you. This is the reason for the little extra window that appears if you run the above demonstration.

To learn how to use Tkinter and all the predefined dialogs, learn from the best:

Tkinter: http://effbot.org/tkinterbook/
Dialog-description: http://effbot.org/tkinterbook/tkinter-standard-dialogs.htm

If you have questions, feel free to ask. I'm pretty familar with Python and Tkinter.




jenay posted Wed, 18 June 2008 at 3:03 AM

Hi, thank you very much - very usefull, just what I needed :)
I did some tests and read some chapters of the tkinter manual (thanks for the
links).
JoeK