user2483250
user2483250

Reputation:

tkinter nothing runs after mainloop()

Currently I am creating a small GUI that guides a user through a configuration of a piece of equipment. You run the program, you select the desired configuration and it sends you to another window in which you receive directions on how to set up the piece of equipment in order to run the test from your computer (via serial). While it was working before, something has changed and I can't figure out what. This is my code for the window in question. all file paths are correct. the program which runs the serial configuration works. I have narrowed down the issue to where it will not run the test outside of mainloop(). When selecting to run the configuration, this window in question will pop up, and at the same time it should start running the configuration. "SLICE_SETUP" is the actual config class and "SLICE" is the test itself.

import sys
from Tkinter import *
from slice_setup import SLICE_SETUP
obj_rcs = SLICE_SETUP()

class pleasewait:

    def pleasewaitbox(self):
        pGui = Tk()
        pGui.geometry("300x100+400+250")
        pGui.title("RSAM BCT")
        plabel = Label(pGui, text= "REDCOM SLICE", fg="red").pack()
        plabel2 = Label(pGui, text= "BCT - Basic Configuration Test", fg= "red").pack()
        plabel3 = Label(pGui, text= "Please wait...", fg= "black").place(x = 120, y = 50)
        plabel3 = Label(pGui, text= "Estimated time: 3 min 6 sec", 
        fg= "black").place(x = 80, y = 70)
        pGui.mainloop()
        obj_rcs.SLICE()

obj_wait = pleasewait()
obj_wait.pleasewaitbox()

Upvotes: 0

Views: 765

Answers (1)

JAB
JAB

Reputation: 21089

Unless mainloop() runs in its own thread/process, you won't be able to do anything outside of it until the main window is destroyed. See https://stackoverflow.com/a/8685760/138772

My suggestion would be to bind a method to the Activate event for pGui that would call obj_rcs.SLICE() and then debind itself from the gui so that it isn't run every time window focus is changed. (Using a flag variable in your pleasewait class could work as well.)

Upvotes: 1

Related Questions