2

I am using Python 3.8 in Spyder. The graphics backend of the IPython console is set to 'automatic'. When I call the IPython Console with a Python algorithm, the window is minimized, so I have to click on it at the taskbar to see it. However, this only happens the first time when I run the algorithm. If I run the algorithm once, click on the window from the taskbar, and then close it, then the next time that I run the algorithm the IPython console is immediately visible. It continues to work fine, but when I restart the kernel I get the same problem again. Here is a MWE:

import matplotlib.pyplot as plt
fig = plt.figure()

How can I make sure that the IPython console always is maximized automatically, even when I run the algorithm for the first time? I am using Python 3.8 in Spyder.

1 Answer 1

0

It can be done using win32gui:

import win32gui, win32com.client
import matplotlib.pyplot as plt
fig = plt.figure()

def Set_to_foreground( hwnd, ctx ):
    if win32gui.IsWindowVisible( hwnd ):
    #The IPython Console will usually have the title 'Figure 1'
        if win32gui.GetWindowText(hwnd)=='Figure 1':
            IPython_console=hwnd
            shell = win32com.client.Dispatch("WScript.Shell")
            shell.SendKeys('%')
            win32gui.SetForegroundWindow(IPython_console)

win32gui.EnumWindows( Set_to_foreground, None )

Note that this only works if no other windows called 'Figure 1' are opened.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.