1

I am new to tkinter and would like to do a UI based on the flags shown. Basically, i would like to close one windows and open another window with the present state or delete the text and show another text with the present state.

class App(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.start()

    def callback(self):
        self.root.quit()

    def run(self):
        self.root = tk.Tk()
        self.root.protocol("WM_DELETE_WINDOW", self.callback)

        label = tk.Label(self.root, text="Start Initialization")
        label.pack()

        self.root.mainloop()


class QQQ:

    def quit(self):
        self.delete(1.0,END)



class Appo(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.start()

    def callback(self):
        self.root.quit()

    def run(self):
        self.root = tk.Tk()
        self.root.protocol("WM_DELETE_WINDOW", self.callback)

        label = tk.Label(self.root, text="Initialization ended")
        label.pack()

        self.root.mainloop()


for i in range(100000):

    time.sleep(0.5)

    print(i)

    if(i==1):

        app = App()

        time.sleep(1)

        qqq=QQQ()

    if(i==10):

        app=Appo()
Khristos
  • 973
  • 2
  • 11
  • 22
CherChuan
  • 33
  • 5

1 Answers1

0

If all you want to do is change the text of the label, then use the config method on the label. The App, Appo, and QQQ classes, as well as the for loop can be combined into a single class as:

import Tkinter as tk #Python 2
#import tkinter as tk #Python 3
import threading
import time


class App(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.root = tk.Tk()
        self.start()

    def callback(self):
        self.root.quit()

    def run(self):
        self.root.protocol("WM_DELETE_WINDOW", self.callback)

        label = tk.Label(self.root, text="Initial Text") # You can use text=""
        label.pack()

        for i in range(100000):
            time.sleep(0.5)
            print (i)
            if i == 1:
                label.config(text="Start Initialization")
                time.sleep(1)
                label.config(text="")
            if i == 10:
                label.config(text="Initialization ended")
        #self.root.mainloop()

app = App()
app.root.mainloop()

It might be better to use the after method of tkinter for time delays instead of time.sleep()

Khristos
  • 973
  • 2
  • 11
  • 22