473,795 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unexplained behavior of tkMessageBox.as kyesno


I have a program with these fragments:

from Tkinter import *
import tkFileDialog
import tkMessageBox

def openProject():
filepath = tkFileDialog.as kopenfilename(f iletypes=(("pro ject files","*.ini") , ("all","*")) )
if filepath:
loadProject(fil epath)

def makeClean():
if tkMessageBox.as kyesno('Make clean', 'Remove all files created by Make?'):
print 'yes'
# more code

If I call makeClean(), I get the yes/no box. If I click 'yes',
it prints 'yes', unless I have called openProject() sometimes
earlier. In the latter case, none of the code following the
askyesno gets executed, whether I click 'yes' or 'no'. It also
happens when I have called openProject() earlier and clicked
'Cancel'.

This error happens on one Linux machine ([GCC 3.3.1 (SuSE
Linux)] on linux2), but not on another ([GCC 2.95.3 20010315
(SuSE)] on linux2). Both have Python 2.3.4. It works fine on
Windows98 with Python 2.4

Anyone any idea what is going on?
--
Peter Kleiweg L:NL,af,da,de,e n,ia,nds,no,sv, (fr,it) S:NL,de,en,(da, ia)
info: http://www.let.rug.nl/~kleiweg/ls.html

Jul 18 '05 #1
4 2410
Peter Kleiweg schreef:
from Tkinter import *
import tkFileDialog
import tkMessageBox

def openProject():
filepath = tkFileDialog.as kopenfilename(f iletypes=(("pro ject files","*.ini") , ("all","*")) )
if filepath:
loadProject(fil epath)

def makeClean():
if tkMessageBox.as kyesno('Make clean', 'Remove all files created by Make?'):
print 'yes'
# more code

I changed the code to this:

def makeClean():
print tkMessageBox.as kyesno('Make clean', 'Remove all files created by Make?')
If I have used openProject(), the function makeClean() always
prints 'False', no matter what I choose.
--
Peter Kleiweg L:NL,af,da,de,e n,ia,nds,no,sv, (fr,it) S:NL,de,en,(da, ia)
info: http://www.let.rug.nl/~kleiweg/ls.html

The Halloween Documents: http://www.opensource.org/halloween/

Jul 18 '05 #2
On Tue, 07 Sep 2004 21:43:02 +0200, Peter Kleiweg wrote:
If I have used openProject(), the function makeClean() always
prints 'False', no matter what I choose.


If I had to guess, I'd say the problem is that you aren't using Tk
correctly. You really need to run

root = Tk()
root.mainloop()

to be confident everything will work as advertised. Which means you'll
need to re-structure your program a bit.

Tk, as GUI toolkits go, is surprisingly effective without its mainloop
running; many GUI toolkits won't even get that far. However, in my
experience, you'll get random-seeming failures from anything that requires
events to work properly, and "mouse clicking" is an event.
Jul 18 '05 #3
Jeremy Bowers schreef:
On Tue, 07 Sep 2004 21:43:02 +0200, Peter Kleiweg wrote:
If I have used openProject(), the function makeClean() always
prints 'False', no matter what I choose.


If I had to guess, I'd say the problem is that you aren't using Tk
correctly. You really need to run

root = Tk()
root.mainloop()

I have that.

The tkMessageBox.as kyesno() is called from a function that is a
callback from a menu item attached to root.

--
Peter Kleiweg L:NL,af,da,de,e n,ia,nds,no,sv, (fr,it) S:NL,de,en,(da, ia)
info: http://www.let.rug.nl/~kleiweg/ls.html

Jul 18 '05 #4
Peter Kleiweg schreef:

I have a program with these fragments:

from Tkinter import *
import tkFileDialog
import tkMessageBox

def openProject():
filepath = tkFileDialog.as kopenfilename(f iletypes=(("pro ject files","*.ini") , ("all","*")) )
if filepath:
loadProject(fil epath)

def makeClean():
if tkMessageBox.as kyesno('Make clean', 'Remove all files created by Make?'):
print 'yes'
# more code


The file tkMessageBox.py that comes with Python has this:

def askyesno(title= None, message=None, **options):
"Ask a question; return true if the answer is yes"
s = _show(title, message, QUESTION, YESNO, **options)
return s == YES
So instead of calling askyesno, I used this:

def makeClean():
r = tkMessageBox._s how('Make clean', 'Remove all files created by Make?', 'question', 'yesno')
print type(r), r

Call makeClean(), click no, result: <type 'str'> no
Call makeClean(), click yes, result: <type 'str'> yes
Call openProject(), click cancel
Call makeClean(), click no, result: <type 'str'> no
Call makeClean(), click yes, result: <type 'bool'> True

Now, how did that happen?

--
Peter Kleiweg L:NL,af,da,de,e n,ia,nds,no,sv, (fr,it) S:NL,de,en,(da, ia)
info: http://www.let.rug.nl/~kleiweg/ls.html

Jul 18 '05 #5

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

Similar topics

0
1430
by: newgene | last post by:
Hi, group, A weird clipboard behavior for your help: ==============Code============== from Tkinter import * import tkMessageBox root=Tk() root.withdraw() root.clipboard_clear()
1
2671
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
5282
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
2551
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....
3
3751
by: peter | last post by:
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...
5
6951
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
13918
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
1405
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
1774
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
9672
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
10214
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
10164
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
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
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
7540
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
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.