473,748 Members | 2,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Throwing the error message in Tkinter

440 Contributor
Hi ,

I would like to throw a error/warning message to the user based on the Inputs given.

Case 1) If the inputs are not given correctly.I have to diplaythe message,saying "Enter the correct inputs"

Case 2) In between the functions,if I am getting a wrong input data ,I have to stop further execution of the application and display the error message " Calculated xyz values are wrong ..."

I hope we have to use "try " and "catch' blocks.

Could anybody provide the snippet of the code for catching the above cases error.

Thanks
PSB
Apr 30 '07 #1
2 2315
bvdet
2,851 Recognized Expert Moderator Specialist
Hi ,

I would like to throw a error/warning message to the user based on the Inputs given.

Case 1) If the inputs are not given correctly.I have to diplaythe message,saying "Enter the correct inputs"

Case 2) In between the functions,if I am getting a wrong input data ,I have to stop further execution of the application and display the error message " Calculated xyz values are wrong ..."

I hope we have to use "try " and "catch' blocks.

Could anybody provide the snippet of the code for catching the above cases error.

Thanks
PSB
It seems you want your code to continue, but loop back to give the user a chance to input valid data. This may not be the best way:
Expand|Select|Wrap|Line Numbers
  1. while True:
  2.     data = raw_input("Enter data")
  3.     if test_user_entered_data(data): # pass to a test function, return True if valid
  4.         break # continue to process the valid data
  5.     else:
  6.         print "You entered invalid data. Please enter again."
Apr 30 '07 #2
bartonc
6,596 Recognized Expert Expert
Hi ,

I would like to throw a error/warning message to the user based on the Inputs given.

Case 1) If the inputs are not given correctly.I have to diplaythe message,saying "Enter the correct inputs"

Case 2) In between the functions,if I am getting a wrong input data ,I have to stop further execution of the application and display the error message " Calculated xyz values are wrong ..."

I hope we have to use "try " and "catch' blocks.

Could anybody provide the snippet of the code for catching the above cases error.

Thanks
PSB
Creating your own Exception classes is a very useful thing to learn:
Expand|Select|Wrap|Line Numbers
  1. class MyAppError(exception):
  2.     def __init__(self, message):
  3.         self.message = message
  4.  
  5.     def __repr__(self):
  6.         return self.message
  7.  
  8. try:
  9.     if A + B + C != ExpectedResult:
  10.          raise MyAppError(" Calculated xyz values are wrong ...")
  11. except MyAppError, msg
  12.     print msg
You can also raise any type of built-in exception the same way. Another trick is to:
Expand|Select|Wrap|Line Numbers
  1. try:
  2.     aValue = aList[anIndex]
  3. except IndexError:
  4.     # do something usefull
  5.     raise
Which allows you to intercept the error and then let it continue to propigate up the call chain.
Apr 30 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
10934
by: Otto Krüse | last post by:
Hi everyone, I'm building a GUI in which I want, amongst other things, for people to fill in there postal code. The postal codes of my country (Holland) are in this format: 1234 AB So for the input I use two entry widgets, one of a length of (characters) for the numbers and one of lenght 2 for the letters. What I don't like is that although the visible part of the widgets thus are 4 and 2 characters, users can actually input more...
0
1733
by: Laurent Pointal | last post by:
Bienvenue sur la liste Python francophone, hébergée par l'AFUL, ou sur le newsgroup fr.comp.lang.python ("fclp"). Votre abonnement à cette liste de diffusion ou votre lecture de fclp montrent un intérêt pour le langage Python et ce qui tourne autour. Après quelques temps de lecture, vous serez sûrement amené à poster vous aussi un message. Voici quelques conseils d'utilisation, suivi d'une série de liens à partir desquels vous ...
40
13522
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
5
3562
by: Ben Kovitz | last post by:
Hi, I just tried to run Tkinter on OS X 10.3.9 under Python 2.4.3, and I'm getting a bus error as soon as I call Tk(). Googling has turned up info other Tkinter bus errors, but not this one that occurs right away, before doing anything fancy. Tk/Tcl is definitely installed on my computer, as verified by running "wish" and seeing the window come up. "info patchlevel" returns 8.4.5. Here's the tail of the output from python -v:
2
1966
by: Kevin Walzer | last post by:
I am trying to structure a Tkinter application with classes instead of just with simple functions, but I'm not sure how to call methods from my main class. My main class is packetstreamApp(). Within that class I call various methods, including drawGUI() and authorizeDump(). My problem comes when I try to call authorizeDump from the Tkinter menu. Here is the code that calls authorizeDump(): self.packetmenu.add_command(label="Start...
2
2097
by: BartlebyScrivener | last post by:
Finally started trying to build a simple gui form for inserting text data into a mysql db of quotations. I found this nice Tkinter tutorial, http://www.ibiblio.org/obp/py4fun/gui/tkPhone.html but midway I'm getting an error. from Tkinter import *
1
2440
by: alivip | last post by:
I integrat program to be GUI using Tkinter I try browser direction as you can see # a look at the Tkinter Text widget # use ctrl+c to copy, ctrl+x to cut selected text, # ctrl+v to paste, and ctrl+/ to select all # count words in a text and show the first ten items
3
211
by: Anish Chapagain | last post by:
from Tkinter import * root=Tk() f=Frame(root,height=200,width=200) b=Button(f,text="quit",command=f.quit) f.pack() root.mainloop() -------------------------------------------------- from Tkinter import * import sys
21
1715
by: Chris M. Thomasson | last post by:
Is it every appropriate to throw in a dtor? I am thinking about a simple example of a wrapper around a POSIX file... ________________________________________________________________________ class file { FILE* m_handle; public: // ; ~file() /* throw() */ {
0
8832
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
9561
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...
1
9332
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
8252
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
6799
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
4608
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...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
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.