Fri, Nov 22, 7:24 AM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: saving to a new file with tkinter


dorkmcgork ( ) posted Sat, 03 November 2012 at 10:19 PM · edited Fri, 30 August 2024 at 9:37 PM

hola folks i'm new at python, and fighting my way through tkinter.  using 2.7 in 2010

so here's what i have:

import Tkinter,tkFileDialog

root = Tkinter.Tk()
file = tkFileDialog.askopenfile(parent=root,mode='rb',title='Choose a file')
if file != None:
    data = file.read()
    file.close()
    print "I got %d bytes from this file." % len(data)
    print data
root.mainloop()

for opening a file.  works great.

but all i have found for saving a file is this:

 

import Tkinter,tkFileDialog

myFormats = [
    ('text','*.txt'),
    ]

root = Tkinter.Tk()
fileName = tkFileDialog.asksaveasfilename(parent=root,filetypes=myFormats ,title="Save the file as...")
if len(fileName ) > 0:  
    print "Now saving"

root.mainloop()

 

but no luck.  it says it's saving (lol, 'cause i told it too) but it does not save anything.  i've finegeled it many ways with my itty bitty knowlege set but to no avail.  can anyone point me in the correct direction? 

go that way really fast.
if something gets in your way
turn


PhilC ( ) posted Sun, 04 November 2012 at 3:21 AM

The second dialog just returns the file path of where you want the data to be saved to. You still need to write it to the file.

f = open(filepath, 'w')
f.write(data)
f.close()

If you are working with current versions of Poser you may find wxPython preferable to Tkinter. Also note that Poser has its own built in file dialogs.

Hope that helps.


dorkmcgork ( ) posted Sun, 04 November 2012 at 9:25 PM

gratzi! phil

go that way really fast.
if something gets in your way
turn


Privacy Notice

This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.