tkMessagebox.askyesno always returns False

P

peter

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>
 
J

James Stroud

peter said:
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>

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

http://www.jamesstroud.com/
 
P

peter

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
 
P

peter

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(self,ask_file_name=1):

#if ask_file_name get tagfile name
if ask_file_name:
a=fd.askopenfilename(title='Tag
File',initialdir=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.delete(0,tk.END)
self.entTag.insert(0,os.path.split(self.tagfile)[1])

# read file
self.taglist=[]
try:
fp=file(self.tagfile,'r')
while 1:
a=pstring(fp.readline())
if a.text=='': break
a.stripcrlf()
self.taglist.append(a.text)
fp.close()
except:
mb.showerror(self.tagfile,'Error reading from tag file')
self.show_taglist()
</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.lstFiles.size()):
f=self.lstFiles.get(i)
if f in self.taglist:
self.lstFiles.select_set(i)
self.lstFiles.see(i)


</code>

<code>

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

## set up list of files - element 0 is the path and elements 1
up are the files
## get_listbox_contents(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.lstFiles).get_listbox_contents(1)
exit_flag=0
file_count=len(file_list)-1
if file_count==0:
mb.showwarning(self.title,action+': 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(file_list[0],'Ok to rename %d selected
file(s)' % file_count)
if i==0: exit_flag=1

## etc
<code>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top