0

Writing an automated GUI to rename files by user input.

When I go to popopen the file in subprocess, the tkinter window loses focus, meaning I can't set focus on an entry.

I have tried time.sleep(), to see if I can give the GUI time to load. I have tried to force focus on the GUI.

def load(self):       
        if self.main_counter >= len(list_of_files):
            self.close()
            return

        filepath = list_of_files[self.main_counter]
        filename = os.path.basename(filepath)
        filename_no_ext, ext = os.path.splitext(filename)

        self.process = subprocess.Popen(
            [exts_to_index[ext.lower()]] + [filepath],
            stdout=subprocess.PIPE
            )

        root.title(filename)

        self.entries[0].focus_set()

I need the Tkinter window not to lose focus, and the 1st entry remains selected, when opening adobe alongside.

Dylan Logan
  • 395
  • 7
  • 18
  • 1
    Take a look and see if this helps: https://stackoverflow.com/questions/15944533/how-to-keep-the-window-focus-on-new-toplevel-window-in-tkinter – r.ook Sep 12 '19 at 12:53
  • 1
    Possible duplicate of [Tkinter main window focus](https://stackoverflow.com/questions/22751100/tkinter-main-window-focus) – CommonSense Sep 12 '19 at 13:20
  • @Roca I tried calling grab_set above my entry focus and Adobe is still taking focus. – Dylan Logan Sep 12 '19 at 13:25
  • @CommonSense I have said in the question I have tried force_focus and it didn't work. I review this specific question too. Thanks though. – Dylan Logan Sep 12 '19 at 13:25
  • Please, check this [answer](https://stackoverflow.com/a/47161643/6634373). As far as I know, there's no way to not lose focus for the first time. – CommonSense Sep 12 '19 at 13:31
  • Probably much more cumbersome than you anticipated, but you could get a module to hook into your OS to manipulate the focus on the OS level. e.g. if you're on Windows, `pywinauto` is one option. – r.ook Sep 12 '19 at 13:40

0 Answers0