Spyder: Add a Spyder dark theme

Created on 23 Apr 2015  ·  106Comments  ·  Source: spyder-ide/spyder

I guess this can be achieved bu having custom themes on a OS level, but it would be nice to be able to set Spyder to a dark theme directly in Spyder.

Something like what Dark style sheet provides...

Main Window Ui Feature

Most helpful comment

This was a one liner (using https://github.com/ColinDuquesnoy/QDarkStyleSheet)!

darkstyle

It would need a bit of tweaking to get it to work with the rest ... but what do you guys think?

@ccordoba12, @blink1073, @Nodd, @SylvainCorlay?

All 106 comments

Something like that would be amazing. I am far from experienced enough of a coder to implement something like this, but if there is any testing I can do or help in any other way, please let me know.

This was a one liner (using https://github.com/ColinDuquesnoy/QDarkStyleSheet)!

darkstyle

It would need a bit of tweaking to get it to work with the rest ... but what do you guys think?

@ccordoba12, @blink1073, @Nodd, @SylvainCorlay?

:+1:

I really like it and I'm also +1 for it, but:

  1. First we need to unify syntax highlighting schemes under a single entry in Preferences.
  2. We need to define a dark scheme for the Object Inspector.
  3. We need to integrate it with our (FontAwesome) theme.
  4. We need to decide if we want to fork QDarkStyleSheet as part of the spyder-ide org to maintain it for the rest of time! :-p I mean, if we add this feature there's no coming back ;-)

It seems like too much work for 3.0. Maybe for 3.1 if @goanpeca wants to tackle it?

@ccordoba12:

I agree with all the todos but:

  1. I can do this, if we agree on what is the desired functionality.
  2. @ccordoba12 has to take care of this
  3. @SylvainCorlay has to take care of this
  4. It is an external project, why do we need to maintain it?, we can depend on it (either implicitly or explicitly)

(4.) Because it can become unmaintained at any time :-) Well, we'll fork it when that happens :-p

@ccordoba12 how are the css/style defined in the object inspector?

They're defined in utils/inspector/css

@goanpeca it should be easy to parameterize the qtawesome colors in the new icon manager, but (I think) that you would need to restart Spyder to change themes.

Hmmmm I think we should avoid that :p if possible. Also... why do we need to restart spyder to change themes?

In you screenshot, the icons having grey components don't show well.

  • In file icon_manager.py, we can certainly fetch the colors in a dictionary.
  • But when changing the theme, we would need to ask all the icons to be re-rendered. I was just wondering whether it is the case already, or if we could trigger it.

We should be able to trigger it if it is not the case already.

Yes, except that in our case this would be re-instantiating all the QIcons. I hope it works though.

you would need to restart Spyder to change themes

I think that's unavoidable :-) I really doubt Qt qss stylesheets could be changed on the fly.

@ccordoba12 Yes you can, not directly, but what I have done is overload the paint method so that if it detects that the style has change it will repaint (using the new css you select).

This could be added as a decorator on the paint method to avoid a lot of code repetition.

This is how I managed to get the new global directory combobox to update based on style change

Here and here

Ok, didn't know that :-)

But it seems that it would not recompute the QIcons?

Yes they will :-)

Hmm yes... maybe not :s will look further into it

Dear @goanpeca,

How can I get rid of this terrible editor and console grey borders and make top tabs looks like bottom tabs on Mac?

screen shot 2016-06-01 at 17 00 15

I've added lines:

import qdarkstyle
MAIN_APP.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False))

Version and main components

  • Spyder Version: 3.0.0b2
  • Python Version: 2.7.11
  • Qt Versions: 4.8.7, PyQt4 (API v2) 4.11.4 on Darwin

Dependencies

pyflakes >=0.5.0   :  1.2.3 (OK)
pep8 >=0.6         :  1.7.0 (OK)
pygments >=1.6     :  2.1.3 (OK)
IPython >=3.0      :  4.2.0 (OK)
zmq >=13.0.0       :  15.2.0 (OK)
qtconsole >=4.0    :  4.2.1 (OK)
pandas >=0.13.1    :  0.18.1 (OK)
numpy >=1.7        :  1.11.0 (OK)
sphinx >=0.6.6     :  1.4.2 (OK)
psutil >=0.3       :  4.2.0 (OK)
rope >=0.9.4       :  0.9.4-1 (OK)
jedi >=0.8.1;<0.9.0:  0.8.1 (OK)
matplotlib >=1.0   :  1.5.1 (OK)
sympy >=0.7.3      :  1.0 (OK)
pylint >=0.25      :  1.5.5 (OK)

@azenin, there's nothing you can do about it for now, sorry :-(

We use our own style customizations on Mac. We need to adapt them to make Spyder work with qdarkstyle.

@goanpeca maybe I can style this Qt elements in qdarkstyle?

It depends on which style you load first. But since they are particular to Spyder, I think we should make those adaptations here instead of in qdarkstyle.

@goanpeca, I would appreciate if you can describe how did you make the Spyder dark theme. I'm relatively new to spyder.

I'm a tad lost. Is there the dark theme available? The current bright one hurts my eyes...

There are dark themes available for the Editor in

Preferences > Syntax Coloring

This issue is about a dark theme for the whole interface (and not just the Editor). And that's going to be implemented in Spyder 4 :-)

@ccordoba12, thank you. And what about the one-liner @goanpeca was suggesting? His screenshot looks pretty slick!

@goanpeca is working on a better solution right now. That one liner was just a hack ;-)

... which looks just amazing :drooling_face:

Any Updates on this?

If you are looking for a workaround to a dark theme for the entire application, until Spyder 4 is released, you can try the one liner method mentioned by @goanpeca.
In the spyder.utils.qthelpers module (/path2python/dist-packages/spyder/utils/qthelpers.py), in the qapplication() function, just before return app, add the line
import qdarkstyle; app.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False))

For more information on qdarkstyle see here

Hi all!

I would like to use the @goanpeca solution, how can I do that for Spyder/PySide?

I'm totally new with this.

Thanks

@acaparrelli we no longer "officially" support pyside, but it should be exactly the same. We are working on a better more customizable solution for spyder 4.0.0 :-0)

@acaparrelli

I haven't found any working solution in this topic that describes step by step what you need to do in order to set qdarkstyle theme as the new default theme, so I decided to write one. This little guide almost entirely based on @SebastianHD answer (which is two posts above), but the main statement in his answer will not work if you are using PyQt5. So if you think that your Spyder running on PyQt4 make sure you check out his answer.

1) You have to open qthelpers.py file which in my case was stored in /usr/lib64/python3.5/site-packages/spyder/utils/ directory. Make sure that you opened it as root since it can be read-only for normal users.

2) Add import qdarkstyle statement at start of the file. Make sure to comment this line, so you could find it easily if you would like to get back to standard theme.

3) Find qapplication() function and insert app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) statement just before return app statement. Make sure you comment it for purposes that I've stated above.

4) That's it. Save the file and start Spyder. You just have substituted Spyder's default theme to qtdarkstyle.

Thanks for your help @Akyshnik!

You're welcome!
Here how it is looks like. No need to burn your eyes anymore!
screenshot from 2017-06-24 22 54 54

@Akyshnik thanks for your version also. I'm certainly no expert in the matter. For me your version doesn't work because I'm not using PyQt5 (I'm still running on python 2). But I am certainly using Spyder 3.1.4

screenshot from 2017-06-24 17-06-38

@SebastianHD I updated my comment. Thank you for making this clear.

thank you for the step by step @Akyshnik!

Just wanted to comment that the qdarkstyle hack also works on Windows. Pretty cool :)
Thanks for everyone who contributed to the explanations.
It will be great to see it built-in in the future!

spyder3_windows_darktheme

Doesn't work anymore in Spyder 3.2.0 😥

I am officially working on this now, I need some weeks though

@Akyshnik I'm new to Linux and programming in general. The python course I'm taking asked me to install anaconda and use spyder as an IDE. I would like to use the dark theme to increase the amount of time I can look at the screen without eye strain becoming a problem, but I'm having some issues getting this to work. I'm running a centos7 virtual machine inside of windows7, I'm using anaconda 4.4.0, Sypder 3.1.4, python 3.6.1 and pretty sure I'm also using pyqt 5.6.0.

Following your instructions and then trying to run spyder, I get this error:

ModuleNotFoundError: No module named 'qtdarkstyle'.

I take it to mean that I need to install qtdarkstyle, but I'm having trouble doing that as well. I tried running the command shown on this link ( https://anaconda.org/auto/qdarkstyle ):

conda install -c auto qtdarkstyle

This gives me an error message stating that there is no qtdarkstyle package to install. Now I'm just lost. Any help in getting this to work would be much appreciated.

Edit: Took awhile, but figured it out, starting with "qdarkstyle" and not "qtdarkstyle". Dependencies then became a problem, but found a command to use pip instead of conda, and for some reason, dependencies weren't a problem with it.

One last nitpicky question. Is there a place where I can change the dark color of the IPython console to match the color of the qdarkstyle background?

hi, since the SVG icon issue was closed in favor of this one, here a summary for the IMHO best steps to get SVG icons working painlessly. since you plan to use breeze icons, it should be even easier:

  1. we should use the breeze system for icon colors (the implementation is really easy: you simply parse the icon, and replace the contents of the SVG node having the id #current-color-scheme with some templated CSS)
  2. we can use this system for supporting Qt icon themes and having a embedded icon theme for use on e.g. windows.

i created this repo for the first one.

Thanks to everyone here. Darkness and eye comfort is very important topic to many. I personally have everything dark on my machine, from browsers to web-pages and even the OS is on accessibility mode.

This fix works, I'm using Spyder 3.22 on windows 10 @rubslopes
The only issue is grey icons are hardly visible, not sure I'm gonna invest more time on this. I'll wait for t he official dark spyder.

meanwhile, I'm downloading Pycharm
image

Sorry, where are the CSS defined for the Object Inspector/Help viewer? I'd like to edit this but I can't find it anywhere. Not sure what the comment linked here was referring to. @ccordoba12

https://github.com/spyder-ide/spyder/issues/2350#issuecomment-162386697

I found the file in the source distribution but I can't tell if there's any way to edit the CSS in use by binary distributions of Spyder using a configuration file. Does it have to be _rebuilt_ to change the css?

For those who have the issue of the gray icons being nigh invisible, like MAFiA303 above, changing the icon set from Spyder 3 to Spyder 2 seems to have solved the issue for me. You can do that under Tools --> Preferences --> General --> Appearance Tab --> Icon Theme.

What I want, is to remove the highlight from every row where there is text. Is there a way to do that?

screenshot_20171003_164858

Tools > Preferences > Syntax Coloring > Edit selected > Background > Pick Screen Color. Now click on the editor background color.

10
First, I want to cancel the highlight of Python console.
Second, I want to make the selection in the list clearer.
What can I do to solve the problem?

I do not think that you can cancel the highlight. I tried and I could not found an option. What I did is mentioned on the comment exactly above yours. I actually downloaded a chrome extension that tells you the color of an area on your screen. Then change the background color to the one that you have been found using the extension. So the background and the highlight color is the same. For the Icons problem you can go to Tools --> Preferences --> General --> Appearance Tab --> Icon Theme and there change the Icons from spyder3 to spyder2. Then it is good enough

With Spyder 4 delayed I decided to fix this for myself.

You can modify your own qdarkstyle color scheme using qdarkstyle. You have to recompile it from the OS but all the tools to do this are in the qdarkstyle git.
What follows is a terrible walk through using spyder 3.2.4 and PyQt5 on windows:

Install qdarkstyle and follow the remaining steps laid out by @Akyshnik or whatever gets it working, If you can get Spyder looking "dark" grey then you can change the colors after this point.

Go to the qdarkstyle git and download everything (you need the rc folder (QDarkStyleSheet/qdarkstyle/rc/) and style.qrc and style.qss files in (QDarkStyleSheet/qdarkstyle/).

The color information is stored in the style.qss file as either named colors "darkgrey" or hex #31363b, for example. It looks like this:

QWidget { color: #eff0f1; background-color: #31363b; selection-background-color:#3daee9; selection-color: #eff0f1; background-clip: border; border-image: none; border: 0px transparent black; outline: 0; }

Edit the named and hex colors to your liking. I tried to change colors intentionally at first but couldn't effect the changes I wanted, so I found all the named colors darkgrey and identified greyish hex colors and changed them all to black. darkgrey->black, #31363b ->#000000, as an example. I mostly changed colors that indicated "background-color:"

You are free, of course, to figure out the color name conventions and do something more surgical if you like.

After you've changed the colors how you like, you need to recompile a pyqt[?]_style_rc.py file and replace the existing one. For this we can find the code from "compile_qrc.py" in (QDarkStyleSheet/qdarkstyle/)

def compile_all(): """ Compile style.qrc using rcc, pyside-rcc and pyrcc4 """ # print("Compiling for Qt: style.qrc -> style.rcc") # os.system("rcc style.qrc -o style.rcc") print("Compiling for PyQt4: style.qrc -> pyqt_style_rc.py") os.system("pyrcc4 -py3 style.qrc -o pyqt_style_rc.py") print("Compiling for PyQt5: style.qrc -> pyqt5_style_rc.py") os.system("pyrcc5 style.qrc -o pyqt5_style_rc.py") print("Compiling for PySide: style.qrc -> pyside_style_rc.py") os.system("pyside-rcc -py3 style.qrc -o pyside_style_rc.py")

Which one you need depends on the flavor of whatever qt you're using. In my case I use pyqt5 which also happened to be the only code that worked. You can execute this how you like. I'll walk through the simple process I used to get it done without unnecessary complication.

Move your style.qrc, edited style.qss, and the rc folder into its own folder. I used C:\qdarkBlackmod

start a python interactive terminal and do:
import os

now change the working directory to the folder you created:
os.chdir("C:/qdarkBlackmod")

then all you need to do is run whatever flavor you need from above. For me:
os.system("pyrcc5 style.qrc -o pyqt5_style_rc.py")

You'll have created a new file in your folder called "pyqt5_style_rc.py" (or whatever flavor you used). For me this file was about 87 KB. Now just search your system and replace the file with the same name (make a backup!). Based on my setup the original was located at:
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\qdarkstyle

Here is my result:

image

Or you can use the attached .txt file if you want what I have (and you trust me). Change the extension from .txt to .py:
pyqt5_style_rc.txt

Cheers!

P.S.
If your backgrounds aren't matched as @KarenPHS points out (solved by @AntonisKoutounids), you may need to change this in your Syntax coloring options. Here are mine:

image

I used the old method to get this "working" but did not care for the fact that the "Help" tab did not have the color scheme applied to it.
Will this method (or the version 4 implementation) make everything follow the theme?

Thanks

The help tab will inherit the color scheme so long as you switch from Rich text to Plain Text. If i look (naively I might add) at the difference between rich text and plain text implementation in spyder/help.py I see (Edited down to what I think matters here):

class RichText(QWidget):

    def set_font(self, font, fixed_font=None):
        """Set font"""
        self.webview.set_font(font, fixed_font=fixed_font)

class PlainText(QWidget):

    def set_font(self, font, color_scheme=None):
        """Set font"""
        self.editor.set_font(font, color_scheme=color_scheme)

    def set_color_scheme(self, color_scheme):
        """Set color scheme"""
        self.editor.set_color_scheme(color_scheme)

The rich text implementation in Spyder doesn't look for the color scheme. We can see PlainText pulls color_scheme for self.editor.set_font and self.editor.set_color_scheme. In RichText it uses fixed_font and doesn't seem to look for any other color schemes. It may be a limitation in Sphinx or... ? Perhaps the creators can provide more input.

That's my guess as to why you wont see those colors change with the dark UI mod above in RichText formatting. It does work for PlainText though.

Thank you for the reply sir.

Switching to plain text was the key.

Mahalo & aloha
Dave

On Thu, Dec 7, 2017 at 8:52 PM, Kenneth Dudley notifications@github.com
wrote:

The help tab will inherit the color scheme so long as you switch from Rich
text to Plain Text. If i look (naively I might add) at the difference
between rich text and plain text implementation in spyder/help.py I see
(Edited down to what I think matters here):

class RichText(QWidget):

def set_font(self, font, fixed_font=None):
    """Set font"""
    self.webview.set_font(font, fixed_font=fixed_font)

class PlainText(QWidget):

def set_font(self, font, color_scheme=None):
    """Set font"""
    self.editor.set_font(font, color_scheme=color_scheme)

def set_color_scheme(self, color_scheme):
    """Set color scheme"""
    self.editor.set_color_scheme(color_scheme)

The rich text implementation in Spyder doesn't look for the color scheme.
We can see PlainText pulls color_scheme for self.editor.set_font and
self.editor.set_color_scheme. In RichText it uses fixed_font and doesn't
seem to look for any other color schemes. It may be a limitation in Sphinx
or... ? Perhaps the creators can provide more input.

That's my guess as to why you wont see those colors change with the dark
UI mod above in RichText formatting. It does work for PlainText though.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/spyder-ide/spyder/issues/2350#issuecomment-350158059,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AgwRrQ6SrEIds-PFvpK69leOIbgh1CbDks5s-KR_gaJpZM4EG0he
.

@CyanBC, the Help plugin uses its own CSS files and they don't follow the scheme declared in the Editor. You can find them in spyder/utils/help

To round out my customizations here is a Dark (black) themed help (Rich Text) .css update as @ccordoba12 directed towards. If you want to edit your own simply open and directly edit the
default.css
file located in your Spyder install. In my case that was:

C:\Program Files\ArcGIS\Pro\bin\Python\pkgs\spyder-3.2.3-py35_0\Lib\site-packages\spyder\utils\help\static\css

If you don't want to do that, you can use the one I customized:
default.txt
Change the extension from .txt to .css and replace (don't forget to backup!) the existing file.

My result:
image

Save these customized color files elsewhere as well, since an update will (probably) overwrite them.

Cheers!

Hi everyone,

I tried the qdarkstyle method on Anaconda Spyder 3.2.4/Ubuntu 16,04 without any change in the theme upon restart.

I found another way though, that might be of interest at least in principle to someone who like me, can't go the recommended route, so I thought I'd share...

Just one one word about Spyder before I do that : for a scientist/researcher/professional it is a necessary tool, indispensible, stable, feature rich and simple to use - was sorry to hear about the financial difficulties and the delays this will cause. When you see all the rubbish being sold for thousands of dollars out there - 40K a year doesn't seem like a lot to ask for these great guys, and, I hope this will be resolved soon (IBM, Apache, GNU ??) - because this community really needs Spyder to live on.

Ok, in Ubuntu you can take a standard theme like Ambience and copy the theme folder (renaming it) to /.local/themes. There is a GTK3 and a GTK2 folder inside. Open the main.css (or the main files where the ones where the colors are defined) in Gedit. The first line(s) in both defines 4 base colors for the theme. Swap the colors between the pairs and Ambience generates a create looking dark theme systemwide for GTK2/3 apps.

Next step : install qt5ct from Synaptic. Open that and select the GTK+ option which points to the GTK 2 options we set in our reworked Ambience in the first step (if qt5ct gives an error about an env variable just do : export QT_QPA_PLATFORMTHEME=qt5ct at a terminal where you are doing all this). Save and exit qt5ct and now every qt5 app will point to the system GTK2 theme.

Make sure you have the Ubuntu repo Spyder installed (not the Anaconda one, I don't know how to set the systemwide GTK in that). Open it and it should have the dark theme (now just choose the dark options you like for the editor, panel). So should things like Inkscape etc.

screenshot from 2017-12-11 20-34-10

I found this more consistent - only snag is that Spyder 1.2.8 (much better than any alternative even at that version!) is what I am limited to on 16.04 and we use the default system Python (but I think you can get it to use Anaconda as well) : but the idea should work on any of the latest Ubuntu's where Spyder is more recent.

If anyone is interested in clarification - just ask please.

Cheers

PS Spyder 2.3.8 that should be, sorry

NB: @SebastianHD / @Akyshnik Solutions work, but if you're going to do it on Windows with Notepad++, be sure to edit the python file with SPACES and not a tab.
On Windows the file is under "\Anaconda3\pkgs\spyder-3.2.0-py36_0\Lib\site-packages\spyder\utils" (check the spyder/python version)

For people that are new to programming (like me), there are no exact details how and what to change in spyder package in order to have the desired effect of your work.
After the installation of qdarkstyle,

  • find spyder.py (in ubuntu 16.04 and python3 is \usr\lib\python3\dist-packages\spyderlib)
  • add imports (you need superuser rights to edit it)
    import qdarkstyle
    from PyQt4 import QtGui (PyQt4 is mine lib check here for others)
  • in Main Window section at def __init__ add
    self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt()) (again pyqt depends of your libs)
    Hope that helps.

Where is the install package OR how do you install qdarkstyle?

i updated to 3.5 and this happened,
every other app still has the default dark t

heme,
even visual studio code!
screenshot from 2018-08-07 16-45-30

whats the easiest way back to a fully dark spyder?

Unfortunately none of these methods worked for me. I am using Spyder 3.2.8 with the default Anaconda package on Windows 10. Can someone suggest an easier way please. It's hard to understand as a beginner in Python. I have tried different IDEs but Spyder is the fastest. So I am not going to use other IDEs. Also, most of the things on my PC are set to a dark theme, including chrome using some extensions. So, I don't want to turn blind by using Spyder in this default glaring white colour.

@gkbalas thank you for your write-up. Unfortunately, for those of us using Spyder through Anaconda, it does not look like there is a dedicated spyder.py file anymore (I could not find one using 'find . -name "spyder.py").

EDIT: I figured it out, here's what I did (I'm an Anaconda user, but it should probably work for others, just make-sure your PyQts are up-to-date).

Find ~/.anaconda3/lib/python3.6/site-packages/spyder/app/mainwindow.py

Add: import qdarkstyle but NOT the from PyQt... line gkbalas suggested.

Then, find def __init__ in the class MainWindow section and add in self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()).

Save, and spyder should start with a new snazzy dark theme.

I struggled somewhat to figure out what to do on my install on Windows10 with Anadonda, so I'll add to the list of instructions.

  1. Install qdarkstyle with pip pip install qdarkstyle
  2. Locate your Spyder install. For me it's: C:\Users\alwayssummer\AppData\Local\Continuum\anaconda3\pkgs\spyder-3.2.8-py36_0\Lib\site-packages\spyder\app
  3. In that folder, make a backup of mainwindow.py, just in case you do stuff wrong.
  4. Edit mainwindow.py, making the changes documented by @ThosV above.

    Add: import qdarkstyle but NOT the from PyQt... line gkbalas suggested.
    Then, find def __init__ in the class MainWindow section and add in self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()).
    Save, and spyder should start with a new snazzy dark theme.

    If you're like me, you might wonder where to put self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()). After the line QMainWindow.__init__(self) worked for me.

  5. In Preferences, change your Syntax coloring to Spyder Dark and Icon Theme to Spyder 2.

Edit: @MausamLondon I hope this helps.

@alwayssummer While your instructions were very nice and clear, nothing changes when I start Spyder. I am using Spyder 3.2.6 with Anaconda and a Python 2.7 installation. Any suggestions? Thanks!

@acmelhorn what is your OS?

Sorry! W10

@alwayssummer @acmelhorn Worked fine for me on a fresh windows 10.

It should work... I've just tested it on Win10 with Spyder 3.2.6 with Anaconda and a Python 2.7 in a new environment.

You have edited the mainwindow.py file for the right version of Spyder and Python you are using in the spyder-3.2.6-py27_0 folder right? Do you have any error message when starting spyder?

@jnsebgosselin My filepath ...\Anaconda2\pkgsspyder-3.2.6-py27_0\Lib\site-packages\spyder\appmainwindow.py and I am getting no errors

Code I have changed:

# =============================================================================
# Stdlib imports
# =============================================================================
from __future__ import print_function

import atexit
import errno
.
.
.
import traceback
import qdarkstyle # updated

and

#==============================================================================
# Main Window
#==============================================================================
class MainWindow(QMainWindow):
    """Spyder main window"""
    DOCKOPTIONS = QMainWindow.AllowTabbedDocks|QMainWindow.AllowNestedDocks
.
.
.
    def __init__(self, options=None):
            QMainWindow.__init__(self)
        self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) # updated

@jnsebgosselin My filepath ...\Anaconda2\pkgsspyder-3.2.6-py27_0\Lib\site-packages\spyder\appmainwindow.py and I am getting no errors

Code I have changed:

# =============================================================================
# Stdlib imports
# =============================================================================
from __future__ import print_function

import atexit
import errno
.
.
.
import traceback
import qdarkstyle # updated

and

#==============================================================================
# Main Window
#==============================================================================
class MainWindow(QMainWindow):
    """Spyder main window"""
    DOCKOPTIONS = QMainWindow.AllowTabbedDocks|QMainWindow.AllowNestedDocks
.
.
.
    def __init__(self, options=None):
            QMainWindow.__init__(self)
      self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) # updated

I have the same problem as well. No error, no dark theme.

Thank you @olundberg for confirming @acmelhorn's issue.

Maybe this is happening because you are both using Anaconda2...

What happens if you add a assert False after the self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) # updated? Does Spyder still start without any problem?

@ccordoba12 what do you think could explain this? I do not think the problem is with Spyder but more with Anaconda that is not syncing things across envs and pkgs.

No idea, sorry.

Thanks @ccordoba12. Well, I do not know either why this is not working without even raising an error or something...

My only guess is that maybe the mainwindow.py file needs to be modified instead in : .\Anaconda2\Lib\site-packages\spyder\app or .\Anaconda2\envs\<your env name>\Lib\site-packages\spyder\app if it is not working when doing it in the pkgs.

With macOS Mojave with dark mode upcoming and spyder 4.0beta out with no dark mode yet, can someone elaborate on the dev status of this issue? Is there a a fork running? Besides finding a nice solution to dark mode without the above tinkering, maybe a shortcut to change or even a query to macOS if dark mode is running would be possible...

@jnsebgosselin and @olundberg making the changes in mainwindow.py in : .\Anaconda2\Lib\site-packages\spyder\app got it to work. Thank you!

@acmelhorn Great! Thanks for testing it and reporting back!

Here are some results I have using QDarkStyle, some changes in QDarkStyle also can provide better visualization for the dropdown, and textbox. https://github.com/ColinDuquesnoy/QDarkStyleSheet/issues/90

To use QDarkStyle is two line changes in the spyder/app/mainwindow (not the best place, just for testing) highlighted inside the screenshoots. I think it is a nice and simple idea to have this as an option inside the Spyder (window theme selection dropdown menu). It should be a optional package. And now we (QDarkStyle) are using QtPy also. So, no compatibility problems.

I've tested using Spyder 3.3.2-dev, Anaconda 4.4, Python 3.6, Linux Ubuntu 16.04.

The problems reported before in this post may have been corrected. @jnsebgosselin, @olundberg

The most problematic is the new icon package (spyder3) that does not work with the dark background. Using the version Two it is pretty nice. Some adjusts should be make in the editor style to match the backgroud...may providing a QDarkSytle theme for the editors too.

Check these screenshoots, using icon package Spyder v2

screenshot linux 2018-09-28 11 12 48

Configuration

screenshot linux 2018-09-28 11 13 15

Editor theme selected, I've changed the background to match

screenshot linux 2018-09-28 11 13 37

Then using the Icon package Spyder v3

screenshot linux 2018-09-28 11 16 03

Configuration

screenshot linux 2018-09-28 11 16 19

Tnksss

@dpizetta, QDarkStyle looks really good in Spyder! I'll assign some resources to implement this solution for Spyder 4 and make it work with the Spyder 3 icon theme.

Just a note: I've used an old version call in the screenshot. As I mentioned, we are using qtpy. Thus, you need to use qdarkstyle.load_stylesheet_from_environment(), it gets from the qtpy. No need for qdarkstyle.load_stylesheet_from_pyqt5() as in the example. In the QDarkStyle V3 it would be qdarkstyle.load_stylesheet().

Black themes are the best for the programmers' eyes heheh.

TKs

Black themes are the best for the programmers' eyes heheh.

Totally agreed!

I am using Anaconda to launch spyder. I used conda install -c auto qdarkstyle to install qdarkstyle. And have this error.

  • python=3

    • qdarkstyle -> python=2.7

Please Help!
New to python and Spyder

To add to this topic: On macOS, there is the option to call
defaults read -g AppleInterfaceStyle
it either prints "Dark" or a an error depending on dark mode. If dark mode is implemented, it might be a good idea to connect it to the OS dark mode setting.

Hey everyone,

worked perfectly for me. Thanks so much!

The background colour for the code/text, however, did not align with the style sheet and I did not know how to check the background colour in terms of HEX or HTML.

So, if you struggle, try this:

  1. Download the free programme "PicPick"
  2. Choose ColourPicker and hover over the background of the editor where NO code is
  3. Check the HTML code and the RGB values
  4. Go to Spyder > Tools > Preferences > SyntaxColoring
  5. Select your preferred theme or custom theme
  6. Choose "Edit selected"
  7. Match values in Background > Background, with the current qdarkstyle sheet it should be "#232629"
  8. Enjoy the darkness!

As @Wurtzinator said, background color set to #232629 worked for me for the syntax coloring.

Much,much better.Thanx

Anaconda3 users on Windows 10 (last step makes it chill!!!)

1) Download qdarkstylesheet (from goanpecas link above)
2) Using anaconda prompt or cmd prompt....>>> python
3) at >>> pip install qdarkstyle
4) Next find spyder in your Anaconda installation dir....\Anaconda3\Lib\site-packages\spyder\app
5) in /app....find mainwindow.py
6) open that file with text editor(spyder or any other)
7) Where all the import statements are(up top) add to the list import qdarkstyle
8) Scroll on down till you find the MainWindow class section
9) find def __init__*(self, options=None):*
QMainWindow.__init__(self)
add:
self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
10) save
11) Start Spyder and In Preferences, under 'Syntax coloring' change 'scheme' to Spyder Dark and under 'General' change Icon Theme to Spyder 2.
12)Almost forgot EPICNESS go back to 'syntax coloring' under 'create new scheme' change 'background' color to #232629 you may have to restart don't remember.

self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())

It is better to use int he final version

style = qdarkstyle.load_stylesheet_from_environment()

So, it gets the qt_api from QtPy environment variable. Thus, people not get problems with they use pyside2 in place of pyqt5

Ok people, I need help:

I got the qdarkstyle to work in Spyder 3 for Python 2 and then 3 a while back, but then had to reinstall the entire conda environment.

conda info here:

image

After a fresh install, I now tried to get it to work again, but it does not work, and I do not know why.The code just seems to break:

When I add the 'import qdarkstyle' line, it is all fine until then and Spyder 3 opens normally.

The moment I add the 'self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())' line, Spyder 3 will not start. When I delete that line again, it starts normally.
I have tried several different indentations, but still to no avail.

What am I missing?

capture

@dpizetta I tried your suggestion instead, but do not know where I should put this:
'style = qdarkstyle.load_stylesheet_from_environment()'

I tried it at the same spot as the other command, i.e. under the section of

init**(self, options=None):

QMainWindow.init(self)

@Wurtzinator
I first tried the line changes to mainwindow after finding spyder here.. ...\Anaconda3pkgsspyder-3.2.6-py27_0\Lib\site-packages\spyder\appmainwindow.py
That didn't work....I got nowhere till I did it to mainwindow here...
.....\Anaconda3\Lib\site-packages\spyder\appmainwindow.py

That second location made the difference for whatever reason be sure to select spyder2 and Spyder dark themes....and a restart.

hope it works.

@kaneman100

I had the same issue when I changed the file several months ago, and then it worked.

But I made sure this time to change the correct file, i.e. \Anaconda3\Lib\site-packages\spyder\appmainwindow.py

and it still does not work :(

Hi @kaneman100 and @Wurtzinator, did you have some more info from logging from the debug mode?

If not, try to add some

    try:
        os.environ['QT_API'] = 'pyqt5'
        import qdarkstyle
    except Exception as err:
        print("Qdarkstyle not found for using black theme:  %s" % err)
    else:
        style = qdarkstyle.load_stylesheet_from_environment()
        app.setStyleSheet(style)

Note the change: qdarkstyle.load_from_environment(), so it gets the qt api (pyside, pyqt, etc) from the QT_API environment variable, same used for QtPy, so you need to make sure that this variable is set before setting using this function (qdarkstyle.load_from_environment()).

I'm using in spyer/app/mainwindow.py

#==============================================================================
# Utilities to create the 'main' function
#==============================================================================
def initialize():
    """Initialize Qt, patching sys.exit and eventually setting up ETS"""
    # This doesn't create our QApplication, just holds a reference to
    # MAIN_APP, created above to show our splash screen as early as
    # possible
    app = qapplication()

    # --- Set application icon
    app.setWindowIcon(APP_ICON)

    #----Monkey patching QApplication
    class FakeQApplication(QApplication):
        """Spyder's fake QApplication"""
        def __init__(self, args):
            self = app  # analysis:ignore
        @staticmethod
        def exec_():
            """Do nothing because the Qt mainloop is already running"""
            pass
    from qtpy import QtWidgets
    QtWidgets.QApplication = FakeQApplication

    # ----Monkey patching sys.exit
    def fake_sys_exit(arg=[]):
        pass
    sys.exit = fake_sys_exit

    # ----Monkey patching sys.excepthook to avoid crashes in PyQt 5.5+
    if PYQT5:
        def spy_excepthook(type_, value, tback):
            sys.__excepthook__(type_, value, tback)
        sys.excepthook = spy_excepthook

    # Removing arguments from sys.argv as in standard Python interpreter
    sys.argv = ['']

    # Selecting Qt4 backend for Enthought Tool Suite (if installed)
    try:
        from enthought.etsconfig.api import ETSConfig
        ETSConfig.toolkit = 'qt4'
    except ImportError:
        pass

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    try:
        os.environ['QT_API'] = 'pyqt5'  # I've set here to make things easy, but there is a right place
        import qdarkstyle
    except Exception as err:
        print("Qdarkstyle not found for using black theme:  %s" % err)
    else:
        style = qdarkstyle.load_stylesheet_from_environment()
        app.setStyleSheet(style)
    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    return app


In the Python 3.6.6, Qt5.9.3, PyQt5.9.2 both your and my code are working, may is something with Py2. I'm waiting for your reply

Mine is working fine. I just had to switch the folder I modified main in.
Wurtinator was having a tougher issue.

On Mon, Nov 12, 2018, 3:37 PM Daniel Pizetta <[email protected]
wrote:

In the Python 3.6.6, Qt5.9.3, PyQt5.9.2 both your and my code are working,
may is something with Py2. I'm waiting for your reply


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/spyder-ide/spyder/issues/2350#issuecomment-438020266,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Ap57ESdIJxFh-7uFwgEf5TwbqsF7oarAks5uudvrgaJpZM4EG0he
.

@dpizetta THANK YOU SO MUCH! It finally worked, yeahiiiiiiiii! Thanks also for the code placement, otherwise I would have been lost. :D

I am now wondering whether it is also possible to get the help windows as well as the JupyterNotebook extension dark? Is that possible?

image

Again, thanks big time!!!

Tks. May they are not applying the style sheet in the notebook. It should use the same widget, as they have menus and toolbars. I saw something mentioned here. Some of them I saw they fixed.

QDarkStyleSheet was a bit too blue for me. I've been trying to recreate Qt Creator's dark flat theme and stumbled on this post
So I copied the code spikespaz provided and put it in darkflat.py in spyder module root (\

    from spyder import darkflat
    palette = darkflat.QDarkPalette()
    palette.set_app(app)

just before the return of initialize function in app/mainwindow.py

It turned out just as I like, but some dark icons became barely visible. So I dug a bit deeper into the code and edited icon function in utils/icon_manager.py

def icon(name, resample=False, icon_path=None):
    theme = CONF.get('main', 'icon_theme')
    if theme == 'spyder 3':
        if not _resource['loaded']:
            qta.load_font('spyder', 'spyder.ttf', 'spyder-charmap.json',
                          directory=_resource['directory'])
            _resource['loaded'] = True
        args, kwargs = _qtaargs[name]
        # <<<<<---------this will make all uncolored icons white------------>>>>>
        if 'color' not in kwargs.keys():
            kwargs['color'] = 'white'
        # <<<<<------------------------------------------------------------->>>>>
        return qta.icon(*args, **kwargs)
    elif theme == 'spyder 2':
        icon = get_icon(name + '.png', resample=resample)
        if icon_path:
            icon_path = osp.join(icon_path, name + '.png')
            if osp.isfile(icon_path):
                icon = QIcon(icon_path)
        return icon if icon is not None else QIcon()

and ended up with this
darkspyder

We already implemented a full dark theme for Spyder 4, and that's going to be available since our next beta (4.0beta2).

For now I'm going to lock this issue because we don't support, endorse, or want people to use hacks against any of our 3.x.x versions because a) they are lost after any update; and b) they could lead to other kinds of problems due to changes in Spyder's internal functionality.

Thanks for understanding!

There are some minor details to be worked out, but I'd say this issue is solved now.

Was this page helpful?
0 / 5 - 0 ratings