-4

I have created GUI using Tkinter and one main script to run. I have some conditions in the main script. if conditions are not satisfied I want to terminate the further execution but keep the GUI active and open. Currently I am using sys.exit() to terminate the script but it is also affecting GUI and Gui goes in not responding mode right away.

for all false conditions in the main script, I am using error dialogue box(messagebox.showerror) on screen and I want to terminate the script once I click OK on the dialogue box.

Could anyone please help me get this working?

Thanks in advance.

alexisdevarennes
  • 5,437
  • 4
  • 24
  • 38
Vi_py123
  • 73
  • 1
  • 9
  • 1
    So simply put an if condition that calls up a dialogue box and trigger sys.exit() when Okay is pressed on the dialog box. – Jason Chia Jan 24 '20 at 12:32
  • 1
    That's exactly what i am doing right now but it also closes GUI. I want to keep GUI open and active the way it was before. – Vi_py123 Jan 24 '20 at 12:36
  • Then you want a dialog box with more than one button. With one button closing everything and the other not closing everything. In what way do you want to stop execution? Are you saying your main thread is processing something and you want to interrupt that processing if certain values are not set? That has nothing to do with Tkinter and more to do with implementing a stop function in your main processing thread. https://stackoverflow.com/questions/10057672/correct-way-to-implement-a-custom-popup-tkinter-dialog-box – Jason Chia Jan 24 '20 at 12:39
  • 2
    It would be very helpful to post some example code to explain what you mean with "script". Is it a function within the same file? Is it another python file? Is it something else? How do you start it? Please read how to create a [mcve] for good information about providing useful code. – fhdrsdg Jan 24 '20 at 12:39
  • My GUI and Main Script are different files. i just want to stop executing main script. – Vi_py123 Jan 24 '20 at 12:40
  • So how do you call it? Do you import it as a module? Do you start a new python process? Please try to create an example, this makes writing a fitting answer much easier. – fhdrsdg Jan 24 '20 at 12:43
  • Let me try to explain it in detail. for ex. in the GUI i am getting different values from user which i am going to use further. I have run button on GUI which basically executes a whole new python script. So when i click run button, It calls the main script, it reads an excel file. now with the variables I have got from GUI, i am doing some checks in the file. if 'condition not satisfied': messagebox.showerror(title="Error", message="display message") sys.exit() this works and stops further execution. but it also closes GUI. I want to keep GUI open. – Vi_py123 Jan 24 '20 at 13:00
  • better add in question minimal working code which shows how you use other script and how you end it. – furas Jan 24 '20 at 13:36
  • if you run some function then use `return` to end this function. – furas Jan 24 '20 at 13:38
  • You're not answering my question and I'm afraid it's impossible to solve your problem without it. How you can end the "main script" depends completely on how you call it. Please read the [mcve] page and edit all the needed info into your question. – fhdrsdg Jan 24 '20 at 14:57

1 Answers1

0

i tried what furas said and it worked.

"if you run some function then use return to end this function. – furas Jan 24 at 13:38"

Vi_py123
  • 73
  • 1
  • 9