473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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>

Jun 21 '06 #1
3 3733
peter wrote:
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/
Jun 21 '06 #2
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

Jun 22 '06 #3

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>

Jun 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Peter Kleiweg | last post by:
I have a program with these fragments: from Tkinter import * import tkFileDialog import tkMessageBox def openProject(): filepath = tkFileDialog.askopenfilename(filetypes=(("project...
1
by: Peter Kleiweg | last post by:
Here is a minimal example that produces the strange results: #### begin code #### #!/usr/bin/env python from Tkinter import * import tkFileDialog import tkMessageBox
1
by: Ajay | last post by:
hi! my application consists of a GUI with a number of functions. One of these runs a server in a separate thread. the thread is started and given the function start_server to execute the...
2
by: Nathan | last post by:
Hi, I've been testing the standard dialog boxes in tkMessageBox under IDLE. If I type for example, tkMessageBox.askyesno('test', 'test'), the dialog box comes up fine but another window also...
4
by: jmdeschamps | last post by:
why is the button sunken when called through a bind method, and not with the command attribute? Thank you! ## Cut'nPaste example from Tkinter import * import tkMessageBox class...
5
by: rahulnag22 | last post by:
Hi, Is there a way to resize the width of the "tkMessageBox.askyesno" dialog box, so that the text does not wrap to the next line. Thanks Rahul
6
by: marcoberi | last post by:
Hi everybody. I have this code snippet that shows a window without a titlebar (using overrideredirect) and two buttons on it: one quits and the other one brings up a simple tkMessageBox. On...
0
by: dudeja.rajat | last post by:
Hi, I'm working on Windows Platform I'm facing some problem with the tkMessageBox. My code is as below: import tkMessageBox import Tix from Tkinter import * if len(installedLibPath) !=...
0
by: Guilherme Polo | last post by:
On Thu, Aug 28, 2008 at 10:29 AM, <dudeja.rajat@gmail.comwrote: It is good to post a short code sample that demonstrates the problem, but it has to run by itself at least. tkMessageBox...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.