Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6171195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:10:18+00:00 2026-05-23T23:10:18+00:00

I have just started using Tkinter for a programming class and am having a

  • 0

I have just started using Tkinter for a programming class and am having a bit of trouble using file dialog handlers. The fileopen and filesaveas methods work correctly, but the filesave method is not.
The specification requires that the filesave method should save to the last saved file; if no file has been saved, then save to the last opened file; else save to the default name quiz_spec.py. For some reason, the first two write calls don’t seem to be saving save the file when they are reached (and aren’t generating any errors either.)
It would be appreciated if someone could please tell me why the same save calls in filesaveas and filesave are functioning differently and also point me to a good example of a tkFileDialog save function.

class FileMan():

    def __init__(self):
        self.lastsave = None
        self.lastopen = None

    def fileopen(self):
        handle = askopenfile(mode = 'r')
        print "name of file you picked = "+str(handle.name)
        self.lastopen = handle
        print "first line of data from file: "+handle.readline()

    def filesave(self):
        if (self.lastsave):
            self.lastsave.write("Save: Some data to save into the file\n")
        elif (self.lastopen):
            self.lastopen.write("Save: Some data to save into the file\n")
        else:
            handle = open('quiz_spec.py', 'w')
            handle.write("Save: This is the new content of test.txt :-)")

    def filesaveas(self):
        handle = asksaveasfile(mode = 'w', defaultextension = '.py')
        print "name of file you picked = "+str(handle.name)
        self.lastsave = handle
        handle.write("SaveAs: Some data to save into the file\n")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:10:19+00:00Added an answer on May 23, 2026 at 11:10 pm

    Pretty clear to me that your file handles self.lastopen and self.lastsave are set to some equivalent of False by the time you call filesave. Did you check that they persist after your fileopen and filesave functions exit? Pretty simple to debug this way, try:

    my_man = FileMan()
    my_man.fileopen()
    my_man.filesave()
    print my_man.lastopen
    print my_man.lastsave
    

    If this doesn’t work, try updating your question with the results of this and we’ll take it from there. Also, you should check if:

    print my_man.lastopen == False and my_man.lastsave == False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started using WPF and am having trouble data binding from the
I just started using Qt and noticed that all the example class definitions have
I have just started using Ruby and I am reading Programming Ruby 1.9 -
I have just started using StructureMap, having previously worked with Spring.Net. I love the
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have just started using silverlight 2 beta and cannot find how to or
I have just started using Boost 1.36. These libraries would be very useful in
i have just started using Moq ver (3.1) and i have read blogs and
I have just started using jQuery and although following code gets the job done,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.