473,804 Members | 3,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tkMessagebox.as kyesno 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 3753
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(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>

Jun 22 '06 #4

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

Similar topics

4
2413
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 files","*.ini"), ("all","*")))
1
2672
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
5285
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 problem is when within start_server i try to display anything using tkMessageBox, nothing gets displayed and my application crashes. Any ideas what i am doing wrong and how to correct it thanks
2
2552
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 appears. I'm guessing this is the parent window of the message box. If I click on either of the yes/no buttons, i get a True/False on the std out and the dialog box closes but the parent window remains and seems to hang. This is on WinXP by the way....
4
3192
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 Vue(object):
5
6952
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
13922
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 Windows (any flavour) the tkMessagebox brings up over the underlying window. On Linux (apparently any flavour) the tkMessagebox brings up under the underlying window. You can drag the popup window near the main window to discover if it's
0
1408
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) != len(listOfLibraries):
0
1777
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 blocks till you finish it, maybe that is what is causing your problem but it is hard to tell what you are doing wrong in that myAppGui without seeing it (preferably reduced code demonstrating the problem).
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10583
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10337
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9160
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.