如何阻止PyCharm切换窗口时自动关闭脚本文件?
Fix for PyCharm CE: Files Closing & Project Tree Collapsing When Switching Windows
Hey there, I’ve run into similar quirky behavior with PyCharm before—let’s walk through some fixes that should get this sorted out for you:
1. Clear PyCharm’s Cache (First Step!)
Corrupted cache is one of the most common culprits for weird UI glitches:
- Go to
File→Invalidate Caches...in the top menu - Check the box for Clear file system cache and local history, then click
Invalidate and Restart - Once PyCharm boots back up, test switching windows again—this often fixes random state-reset issues
2. Rule Out Plugin Conflicts
Third-party plugins can mess with PyCharm’s window state management:
- Open
File→Settings→Plugins - Disable all non-JetBrains plugins (look for the ones not marked with the JetBrains logo)
- Restart PyCharm and see if the problem goes away
- If it does, re-enable plugins one by one until you find the troublemaker—then update or uninstall it
3. Double-Check Window & Tab Settings
Make sure PyCharm is set to remember your session state:
- Go to
File→Settings→Appearance & Behavior→System Settings - Under Window Options, ensure both
Restore window on startupandRemember window size and positionare checked - Next, head to
Editor→General→Editor Tabs:- Even though you adjusted the tab limit, confirm
When tabs exceed limitisn’t set toClose inactive tabs(though this shouldn’t affect single-file cases, it’s worth verifying)
- Even though you adjusted the tab limit, confirm
4. Check for System-Level Window Manager Interference
Sometimes external tools mess with how apps retain their state:
- If you use window management tools (like PowerToys on Windows, Magnet on Mac, or tiling managers on Linux), temporarily disable them
- Test switching windows again—if the problem stops, you’ll need to adjust that tool’s settings to exclude PyCharm
5. Reset PyCharm’s Configuration (Last Resort)
If nothing else works, a fresh config might be needed:
- Close PyCharm completely
- Locate your PyCharm config folder:
- Windows:
C:\Users\<YourUsername>\.PyCharmCE<VersionNumber> - Mac:
~/Library/Application Support/JetBrains/PyCharmCE<VersionNumber> - Linux:
~/.PyCharmCE<VersionNumber>
- Windows:
- Rename the folder to something like
PyCharmCE<VersionNumber>_backup(so you can restore it if needed) - Launch PyCharm again—it’ll create a clean default config
- Test the window switching behavior; if it works, you can gradually reimport your old settings/plugins
内容的提问来源于stack exchange,提问作者AButkov
相关产品推荐
相关产品推荐

