1

I have created a GUI using Tkinter. The GUI is supposed to open a file and read the content. However, if the file content is really big and if certain task takes up a lot of time, it would require a loading screen to let user know it is loading.

This loading screen should also get all the focus and not allow user to click on anything else on the GUI until task is complete. How can I do this?

The following is a simple example of my code. It would be great if I can get a modified version of the code back:

from Tkinter import Tk, Frame, BOTH, Menu

class Application(Frame):
   def __init__(self, parent):
      Frame.__init__(self, parent)
      self.parent = parent
      self.parent.geometry('%dx%d+%d+%d' % (800, 300, 0, 0))
      self.parent.resizable(0, 0)

      menubar = Menu(self.parent)
      self.parent.config(menu = menubar)
      self.fileMenu = Menu(menubar, tearoff = 0)
      self.fileMenu.add_command(label = "Open", accelerator = "Ctrl+O", command = self.onOpen)
      menubar.add_cascade(label = "File", menu = self.fileMenu)
      self.pack(fill = BOTH, expand = True)
   def onOpen(self):
      pass

def main():
   root = Tk()
   Application(root)
   root.mainloop()

if __name__ == '__main__':
   main()
James the Great
  • 941
  • 2
  • 14
  • 46
  • 1
    What, if anything, have you tried so far? – jonrsharpe Apr 22 '14 at 17:14
  • I have been doing some reading, and it seems like I can use after(). Just set a flag once loading is complete then clear the loading screen – James the Great Apr 22 '14 at 17:34
  • Not sure if anybody has a better solution, and easy to implement – James the Great Apr 22 '14 at 17:34
  • This question is a possible duplicate: http://stackoverflow.com/questions/23215226/how-to-pop-up-a-message-while-processing-python?noredirect=1#comment35528625_23215226 You may also want to monitor it. – User Apr 22 '14 at 19:58
  • Are you doing the work in a different thread, or in the same thread the GUI is running in? If it's in the same thread, the best you might hope to do is blit an image on a canvas inside a toplevel. – rpcope1 Apr 22 '14 at 22:01
  • I think I will try doing it with multiple threads, because I want the loading screen to pop up whenever computation is longer than, say 0.5 seconds – James the Great Apr 23 '14 at 16:50

0 Answers0