tkMessagebox.askyesno always returns False

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • peter

    tkMessagebox.askyesno always returns False

    I have a weird problem in some code I am writing. The user selects a
    number of files from a list and then can select an option which will
    rename the selected files. Before the process starts, a yes/no dialog
    box pops up just to confirm.

    Most of the time this works fine, but occasionally it seem the dialog
    box gets into a state where it always returns False, irrespective of
    the button clicked.

    I must be doing something wrong, but I just can't see it! Any
    suggestions?

    <code>

    import tkMessageBox as mb
    :
    :
    if action=='Rename ':
    yn=mb.askyesno( file_list[0],'Ok to rename %d selected
    file(s)' % file_count)
    print 'Response: ',yn # Debug only
    if not yn: exit_flag=1

    </code>

  • James Stroud

    #2
    Re: tkMessagebox.as kyesno always returns False

    peter wrote:[color=blue]
    > I have a weird problem in some code I am writing. The user selects a
    > number of files from a list and then can select an option which will
    > rename the selected files. Before the process starts, a yes/no dialog
    > box pops up just to confirm.
    >
    > Most of the time this works fine, but occasionally it seem the dialog
    > box gets into a state where it always returns False, irrespective of
    > the button clicked.
    >
    > I must be doing something wrong, but I just can't see it! Any
    > suggestions?
    >
    > <code>
    >
    > import tkMessageBox as mb
    > :
    > :
    > if action=='Rename ':
    > yn=mb.askyesno( file_list[0],'Ok to rename %d selected
    > file(s)' % file_count)
    > print 'Response: ',yn # Debug only
    > if not yn: exit_flag=1
    >
    > </code>
    >[/color]

    This problem seems to be beyond the code you provide. Is this part of a
    larger program? Is it possible to show the entire script?

    James

    --
    James Stroud
    UCLA-DOE Institute for Genomics and Proteomics
    Box 951570
    Los Angeles, CA 90095


    Comment

    • peter

      #3
      Re: tkMessagebox.as kyesno always returns False

      It's a moderately large application, and so impractical to post it all.
      I'll have a go at isolating circumstances where this fault occurs then
      post the preceeding code - but not before this evening (London time)
      when I might have some free time.
      Peter

      Comment

      • peter

        #4
        Re: tkMessagebox.as kyesno always returns False


        I've managed to narrow down the circimstances in which the error
        occurs.

        The application is a file manager (not terribly original,I know, but my
        main purpose is to gain experience in using Tkinter). It displays the
        contents of a directory in a list box, and then applies the function
        (in this case rename) to the selected items. There is also a secondary
        list, named tag_list, which can be loaded from disc and used to
        preselect files. If I call the function filter_taglist once, it
        behaves itself but after I load a differenct tag list and repeat, then
        the confirm dialog always returns False and the action fails.

        I'm baffled!!!!

        Code snippets below show
        1. Loading the tag file from disc
        2. Matching the tag file to the main file list
        3. Renaming all selected files

        (comments starting ## have been added in this post)

        <code>

        # Load from file
        def load_taglist(se lf,ask_file_nam e=1):

        #if ask_file_name get tagfile name
        if ask_file_name:
        a=fd.askopenfil ename(title='Ta g
        File',initialdi r=os.path.split (self.tagfile)[0],filetypes=[('Tagfiles','*. tag'),('All
        files','*')])
        if a=='':
        return
        self.tagfile=a
        ## entTag is an entry bix which shows the name of the current
        tag file
        self.entTag.del ete(0,tk.END)
        self.entTag.ins ert(0,os.path.s plit(self.tagfi le)[1])

        # read file
        self.taglist=[]
        try:
        fp=file(self.ta gfile,'r')
        while 1:
        a=pstring(fp.re adline())
        if a.text=='': break
        a.stripcrlf()
        self.taglist.ap pend(a.text)
        fp.close()
        except:
        mb.showerror(se lf.tagfile,'Err or reading from tag file')
        self.show_tagli st()
        </code>

        <code>

        ## This function reads every file in the list box and checks it
        against the tag list
        def filter_taglist( self):
        for i in range(self.lstF iles.size()):
        f=self.lstFiles .get(i)
        if f in self.taglist:
        self.lstFiles.s elect_set(i)
        self.lstFiles.s ee(i)


        </code>

        <code>

        ## This function applies a user specified function to each selected
        file
        def file_control(se lf,action):

        ## set up list of files - element 0 is the path and elements 1
        up are the files
        ## get_listbox_con tents(1) is a function which returns a list
        of
        ## listbox selected contents (instead of just their position
        number)

        file_list=[self.file_path,]+widget(self.ls tFiles).get_lis tbox_contents(1 )
        exit_flag=0
        file_count=len( file_list)-1
        if file_count==0:
        mb.showwarning( self.title,acti on+': No files selected')
        return

        # Initial conditions. If the user cancels, or the conditions
        are insufficient,
        # set an escape flag

        if action=='Rename ':
        i=mb.askyesno(f ile_list[0],'Ok to rename %d selected
        file(s)' % file_count)
        if i==0: exit_flag=1

        ## etc
        <code>

        Comment

        Working...