Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8629267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:45:34+00:00 2026-06-12T08:45:34+00:00

Is it possible, in Tkinter, to break up to the callback on a button.

  • 0

Is it possible, in Tkinter, to break up to the callback on a button. I have a segment of code that, if the user makes a mistake, will cause an error in a specific part of it, however it is within a for loop nested in another for loop and a while loop and can be either 2 or 3 functions deep (with the return of these functions being operated on).

What I would like to do would be to return to the mainloop() when this error is found.

So the code looks a bit like:

from Tkinter import *
def func_call(val_list):
    y = []
    for nn in range(len(val_list)):
       if val_list[nn] < 0:
          print('You entered a value that was too low.')
          break
       else:
          y.append(val_list[nn]+5)
    return(y)
def Button_callback(value):
    val_list = [value,value-1,value-2,value-3]
    y = func_call(val_list)
    for nn in range(len(val_list)):
        print(y[nn])
root = Tk()
Button(root,text='Press me',command=lambda: Button_callback(1)).grid(row=0,column=0) 
root.mainloop()

What this does is identifies that the value is too low, and then breaks out the for loop and then returns the variable “y” to the previous function, which then promptly puts out an error because it expects “y” to be the same length as “val_list”.

What I would like it to do is to effectively return to the button press, so break out of both “func_call” and “Button_callback” with only “You entered a value that was too low.” as an error message.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:45:36+00:00Added an answer on June 12, 2026 at 8:45 am

    This problem doesn’t have much to do with Tkinter, it’s just a normal control-flow question. Typically, the way you handle a situation like this where you want an inner function to stop all processing is to throw an exception, since an exception will propagate up until something catches it.

    For example:

    def func_call(val_list):
        ...
        if val_list[nn] < 0:
            raise ValueError("value too low")
    ...
    def Button_callback(value):
        ...
        try:
            y = func_call(val_list)
        except ValueError:
            return 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to make it so that a Tkinter button calls two function?
Is it possible to call Tcl procedures that have function pointers (or callback functions)
I would like to have a Dropdown Menu in Tkinter, that includes the shortcut
Is is possible to stop a user from minimizing a Python Tkinter window? Or
Possible Duplicate: ImportError when importing Tkinter in Python I have a Mac with Mountain
I am trying to import Tkinter . However, I get an error stating that
I have a gVIM script that parses current buffer and offers user to select
Possible Duplicate: How can I monitor Tkinter buttons when Python is busy? I have
I have a Python Tkinter GUI which solicits file names from the user. I
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.