How to kill currently running functions in tkinter frame while closing it?Is there any way to kill a Thread?Is there a built-in function to print all the current properties and values of an object?How to flush output of print function?How do I return multiple values from a function?How to get the current time in PythonHow to make a chain of function decorators?How do I check what version of Python is running my script?How to remove items from a list while iterating?ttk tkinter multiple frames/windowsWhy does Python code run faster in a function?TkInter Frame doesn't load if another function is called

Can't stopover at Sapporo when going from Asahikawa to Chitose airport?

How do I request a longer than normal leave of absence period for my wedding?

How to respectfully refuse to assist co-workers with IT issues?

Which household object drew this pattern?

Avoiding racist tropes in fantasy

What is wrong about this application of Kirchhoffs Current Law?

C++20 constexpr std::copy optimizations for run-time

Singleton Design Pattern implementation in a not traditional way

What is the best option for High availability on a data warehouse?

Why isn't "I've" a proper response?

Is the term "small" applied differently between piston engine planes and jet engine planes?

Why different interest rates for checking and savings?

Can you feel passing through the sound barrier in an F-16?

What is the history of the university asylum law?

Why in most German places is the church the tallest building?

See details of old sessions

Who was president?

What to say to a student who has failed?

Cross-referencing enumerate item

How would one country purchase another?

Fancy String Replace

Is there any way to keep a player from killing an NPC?

Please help me identify the bold slashes between staves

Are there any music source codes for sound chips?



How to kill currently running functions in tkinter frame while closing it?


Is there any way to kill a Thread?Is there a built-in function to print all the current properties and values of an object?How to flush output of print function?How do I return multiple values from a function?How to get the current time in PythonHow to make a chain of function decorators?How do I check what version of Python is running my script?How to remove items from a list while iterating?ttk tkinter multiple frames/windowsWhy does Python code run faster in a function?TkInter Frame doesn't load if another function is called






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have an export button in tkinter frame, once I click that it exports some data to CSV file. I also have a logout button in the same frame. I have added a function it the logout button to take me main frame and kill the current frame.



Now when I click the export button it will take a minute to complete. Before that if I click the logout button, it takes me to main frame. But the export process is running behind and does not get killed. I'm still getting a csv file.



Once I click logout button, I would like to kill the running export function as well. How do I do that?



I used self.destroy() but the export function is not getting killed.
Below lines are part of my code, the main code has over 400 lines. PageOne is the frame in which I have the export and Logout buttons.



class PageOne(ttk.Frame):
def __init__(self, master):
ttk.Frame.__init__(self, master, height=800, width=1400)

self.logOut_btn = ttk.Button(self, text="Logout", command=self.logOut)
self.logOut_btn.place(x=1280, y=15)
self.export = ttk.Button(self, text="Export", command=self.export_cubeData)
self.export.place(x=620, y=y1+50)
self.exportPath = ttk.Label(self, text="Export Path", font='Helvetica 12 bold')
self.exportPath.place(x=430, y=y1+100)
self.entry_exportPath = ttk.Entry(self)
self.entry_exportPath.place(x=540, y=y1+100, width=450)
final_df = pd.Dataframe()


def logOut(self):
self.destroy()
self.master.switch_frame(StartPage)
with TM1Service(**config['TM1']) as tm1:
tm1.logout()


def setFlag(self):
self.flag = 1

def export_cubeData(self):
exportPath = self.entry_exportPath.get()
for i in range(10):
self.update()
final_df.to_csv(exportPath)









share|improve this question


























  • You're going to need to add some details, ideally a minimal reproducible example. Normally, a function in a Tkinter program that continues to run will freeze the GUI, so the situation you describe is impossible. Perhaps you are running the function in a separate thread, or a separate process?

    – jasonharper
    Mar 27 at 16:20











  • I have shared a sample code, please check if that helps! I use self.update() in a loop so the GUI doesn't freeze. I'm not using multi threading.

    – user1404
    Mar 27 at 16:42







  • 1





    You could set a flag when the button is pressed, and in your export function check this flag every time through the loop, and exit if it's set.

    – jasonharper
    Mar 27 at 16:52











  • I already have a method for setting the flag, could use the same. How stupid I have been for the past hour. Thanks Jason, you got it right.

    – user1404
    Mar 27 at 17:09

















1















I have an export button in tkinter frame, once I click that it exports some data to CSV file. I also have a logout button in the same frame. I have added a function it the logout button to take me main frame and kill the current frame.



Now when I click the export button it will take a minute to complete. Before that if I click the logout button, it takes me to main frame. But the export process is running behind and does not get killed. I'm still getting a csv file.



Once I click logout button, I would like to kill the running export function as well. How do I do that?



I used self.destroy() but the export function is not getting killed.
Below lines are part of my code, the main code has over 400 lines. PageOne is the frame in which I have the export and Logout buttons.



class PageOne(ttk.Frame):
def __init__(self, master):
ttk.Frame.__init__(self, master, height=800, width=1400)

self.logOut_btn = ttk.Button(self, text="Logout", command=self.logOut)
self.logOut_btn.place(x=1280, y=15)
self.export = ttk.Button(self, text="Export", command=self.export_cubeData)
self.export.place(x=620, y=y1+50)
self.exportPath = ttk.Label(self, text="Export Path", font='Helvetica 12 bold')
self.exportPath.place(x=430, y=y1+100)
self.entry_exportPath = ttk.Entry(self)
self.entry_exportPath.place(x=540, y=y1+100, width=450)
final_df = pd.Dataframe()


def logOut(self):
self.destroy()
self.master.switch_frame(StartPage)
with TM1Service(**config['TM1']) as tm1:
tm1.logout()


def setFlag(self):
self.flag = 1

def export_cubeData(self):
exportPath = self.entry_exportPath.get()
for i in range(10):
self.update()
final_df.to_csv(exportPath)









share|improve this question


























  • You're going to need to add some details, ideally a minimal reproducible example. Normally, a function in a Tkinter program that continues to run will freeze the GUI, so the situation you describe is impossible. Perhaps you are running the function in a separate thread, or a separate process?

    – jasonharper
    Mar 27 at 16:20











  • I have shared a sample code, please check if that helps! I use self.update() in a loop so the GUI doesn't freeze. I'm not using multi threading.

    – user1404
    Mar 27 at 16:42







  • 1





    You could set a flag when the button is pressed, and in your export function check this flag every time through the loop, and exit if it's set.

    – jasonharper
    Mar 27 at 16:52











  • I already have a method for setting the flag, could use the same. How stupid I have been for the past hour. Thanks Jason, you got it right.

    – user1404
    Mar 27 at 17:09













1












1








1








I have an export button in tkinter frame, once I click that it exports some data to CSV file. I also have a logout button in the same frame. I have added a function it the logout button to take me main frame and kill the current frame.



Now when I click the export button it will take a minute to complete. Before that if I click the logout button, it takes me to main frame. But the export process is running behind and does not get killed. I'm still getting a csv file.



Once I click logout button, I would like to kill the running export function as well. How do I do that?



I used self.destroy() but the export function is not getting killed.
Below lines are part of my code, the main code has over 400 lines. PageOne is the frame in which I have the export and Logout buttons.



class PageOne(ttk.Frame):
def __init__(self, master):
ttk.Frame.__init__(self, master, height=800, width=1400)

self.logOut_btn = ttk.Button(self, text="Logout", command=self.logOut)
self.logOut_btn.place(x=1280, y=15)
self.export = ttk.Button(self, text="Export", command=self.export_cubeData)
self.export.place(x=620, y=y1+50)
self.exportPath = ttk.Label(self, text="Export Path", font='Helvetica 12 bold')
self.exportPath.place(x=430, y=y1+100)
self.entry_exportPath = ttk.Entry(self)
self.entry_exportPath.place(x=540, y=y1+100, width=450)
final_df = pd.Dataframe()


def logOut(self):
self.destroy()
self.master.switch_frame(StartPage)
with TM1Service(**config['TM1']) as tm1:
tm1.logout()


def setFlag(self):
self.flag = 1

def export_cubeData(self):
exportPath = self.entry_exportPath.get()
for i in range(10):
self.update()
final_df.to_csv(exportPath)









share|improve this question
















I have an export button in tkinter frame, once I click that it exports some data to CSV file. I also have a logout button in the same frame. I have added a function it the logout button to take me main frame and kill the current frame.



Now when I click the export button it will take a minute to complete. Before that if I click the logout button, it takes me to main frame. But the export process is running behind and does not get killed. I'm still getting a csv file.



Once I click logout button, I would like to kill the running export function as well. How do I do that?



I used self.destroy() but the export function is not getting killed.
Below lines are part of my code, the main code has over 400 lines. PageOne is the frame in which I have the export and Logout buttons.



class PageOne(ttk.Frame):
def __init__(self, master):
ttk.Frame.__init__(self, master, height=800, width=1400)

self.logOut_btn = ttk.Button(self, text="Logout", command=self.logOut)
self.logOut_btn.place(x=1280, y=15)
self.export = ttk.Button(self, text="Export", command=self.export_cubeData)
self.export.place(x=620, y=y1+50)
self.exportPath = ttk.Label(self, text="Export Path", font='Helvetica 12 bold')
self.exportPath.place(x=430, y=y1+100)
self.entry_exportPath = ttk.Entry(self)
self.entry_exportPath.place(x=540, y=y1+100, width=450)
final_df = pd.Dataframe()


def logOut(self):
self.destroy()
self.master.switch_frame(StartPage)
with TM1Service(**config['TM1']) as tm1:
tm1.logout()


def setFlag(self):
self.flag = 1

def export_cubeData(self):
exportPath = self.entry_exportPath.get()
for i in range(10):
self.update()
final_df.to_csv(exportPath)






python tkinter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 17:29









martineau

74.9k11 gold badges102 silver badges198 bronze badges




74.9k11 gold badges102 silver badges198 bronze badges










asked Mar 27 at 16:11









user1404user1404

596 bronze badges




596 bronze badges















  • You're going to need to add some details, ideally a minimal reproducible example. Normally, a function in a Tkinter program that continues to run will freeze the GUI, so the situation you describe is impossible. Perhaps you are running the function in a separate thread, or a separate process?

    – jasonharper
    Mar 27 at 16:20











  • I have shared a sample code, please check if that helps! I use self.update() in a loop so the GUI doesn't freeze. I'm not using multi threading.

    – user1404
    Mar 27 at 16:42







  • 1





    You could set a flag when the button is pressed, and in your export function check this flag every time through the loop, and exit if it's set.

    – jasonharper
    Mar 27 at 16:52











  • I already have a method for setting the flag, could use the same. How stupid I have been for the past hour. Thanks Jason, you got it right.

    – user1404
    Mar 27 at 17:09

















  • You're going to need to add some details, ideally a minimal reproducible example. Normally, a function in a Tkinter program that continues to run will freeze the GUI, so the situation you describe is impossible. Perhaps you are running the function in a separate thread, or a separate process?

    – jasonharper
    Mar 27 at 16:20











  • I have shared a sample code, please check if that helps! I use self.update() in a loop so the GUI doesn't freeze. I'm not using multi threading.

    – user1404
    Mar 27 at 16:42







  • 1





    You could set a flag when the button is pressed, and in your export function check this flag every time through the loop, and exit if it's set.

    – jasonharper
    Mar 27 at 16:52











  • I already have a method for setting the flag, could use the same. How stupid I have been for the past hour. Thanks Jason, you got it right.

    – user1404
    Mar 27 at 17:09
















You're going to need to add some details, ideally a minimal reproducible example. Normally, a function in a Tkinter program that continues to run will freeze the GUI, so the situation you describe is impossible. Perhaps you are running the function in a separate thread, or a separate process?

– jasonharper
Mar 27 at 16:20





You're going to need to add some details, ideally a minimal reproducible example. Normally, a function in a Tkinter program that continues to run will freeze the GUI, so the situation you describe is impossible. Perhaps you are running the function in a separate thread, or a separate process?

– jasonharper
Mar 27 at 16:20













I have shared a sample code, please check if that helps! I use self.update() in a loop so the GUI doesn't freeze. I'm not using multi threading.

– user1404
Mar 27 at 16:42






I have shared a sample code, please check if that helps! I use self.update() in a loop so the GUI doesn't freeze. I'm not using multi threading.

– user1404
Mar 27 at 16:42





1




1





You could set a flag when the button is pressed, and in your export function check this flag every time through the loop, and exit if it's set.

– jasonharper
Mar 27 at 16:52





You could set a flag when the button is pressed, and in your export function check this flag every time through the loop, and exit if it's set.

– jasonharper
Mar 27 at 16:52













I already have a method for setting the flag, could use the same. How stupid I have been for the past hour. Thanks Jason, you got it right.

– user1404
Mar 27 at 17:09





I already have a method for setting the flag, could use the same. How stupid I have been for the past hour. Thanks Jason, you got it right.

– user1404
Mar 27 at 17:09












1 Answer
1






active

oldest

votes


















0















I ran into the same problem once. My solution was simply to have my task run on a separate thread, which I flagged as deamon. What this did, is when I destroyed all other threads (read window.destroy), only this task thread was left, and since it was set as a deamon thread, the program was terminated successfully.



Edit :



You should look at this answer if you don't want to end your Python program completely.






share|improve this answer

























  • Thanks, will have a look at this and get back to you.

    – user1404
    Mar 29 at 19:16










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55381829%2fhow-to-kill-currently-running-functions-in-tkinter-frame-while-closing-it%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0















I ran into the same problem once. My solution was simply to have my task run on a separate thread, which I flagged as deamon. What this did, is when I destroyed all other threads (read window.destroy), only this task thread was left, and since it was set as a deamon thread, the program was terminated successfully.



Edit :



You should look at this answer if you don't want to end your Python program completely.






share|improve this answer

























  • Thanks, will have a look at this and get back to you.

    – user1404
    Mar 29 at 19:16















0















I ran into the same problem once. My solution was simply to have my task run on a separate thread, which I flagged as deamon. What this did, is when I destroyed all other threads (read window.destroy), only this task thread was left, and since it was set as a deamon thread, the program was terminated successfully.



Edit :



You should look at this answer if you don't want to end your Python program completely.






share|improve this answer

























  • Thanks, will have a look at this and get back to you.

    – user1404
    Mar 29 at 19:16













0














0










0









I ran into the same problem once. My solution was simply to have my task run on a separate thread, which I flagged as deamon. What this did, is when I destroyed all other threads (read window.destroy), only this task thread was left, and since it was set as a deamon thread, the program was terminated successfully.



Edit :



You should look at this answer if you don't want to end your Python program completely.






share|improve this answer













I ran into the same problem once. My solution was simply to have my task run on a separate thread, which I flagged as deamon. What this did, is when I destroyed all other threads (read window.destroy), only this task thread was left, and since it was set as a deamon thread, the program was terminated successfully.



Edit :



You should look at this answer if you don't want to end your Python program completely.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 27 at 20:05









Olivier SamsonOlivier Samson

5112 silver badges11 bronze badges




5112 silver badges11 bronze badges















  • Thanks, will have a look at this and get back to you.

    – user1404
    Mar 29 at 19:16

















  • Thanks, will have a look at this and get back to you.

    – user1404
    Mar 29 at 19:16
















Thanks, will have a look at this and get back to you.

– user1404
Mar 29 at 19:16





Thanks, will have a look at this and get back to you.

– user1404
Mar 29 at 19:16








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55381829%2fhow-to-kill-currently-running-functions-in-tkinter-frame-while-closing-it%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript