Is there some way to make some words in a Python 3 input get a different color than the default one of the terminal? Like this one:
log 'Hello World'
The word "log" became blue and the string "'Hello World'" became green.
I am answering on the assumption that blue and green, for instance, are something that does not happen now but are something you would like to make happen.
If you are entering code in a system console, such as Command Prompt on Windows or Terminal on Mac and maybe some *nixes, you are unlikely to be able to get Python syntax coloring. The console would have to be able to partially parse Python syntax.
If you are entering code in a code editor that support syntax highlighting and that can parse Python code, then you can get some coloring. Some but not necessarily all will support user customization of colors.
IDLE divides Python code into multiple categories and offers both light and dark background schemes. Users can start with either and change the default colors. In your example, "log" and "'hello'" would be 'normal' and 'string' text. In the built-in themes, normal text is either black (on white) or white (on dark blue) while strings are green. The latter is likely why someone asked whether you are using IDLE. You could make a theme in which normal text is a blue that contrasts with the background.
Related
I have a text editor I'm working on. Using PyCharm. I have line number support (many thanks to Bryan Oakley!) and python syntax highlighting using IDLE Perculator. It works but some of the highlight code is hard to read. Oh yes, using tkinter for GUI support.
Can anyone point me at how to set the colors in IDLE? I use options-configure IDLE and some of the changes work in my project and some don't. For example, disabling the colors in my find funcion in the editor doesn't use the 'found' attribute when I alter the 'found' highlight colors. It only highlights what is found when I set the foreground and background colors.
I would prefer to edit a file so I know what it is highlighting, such as comments, strings, keywords, etc.
The IDLE Perculator works better than all of the highlight code I tested.
Just been trying to work out how to set the highlight colors to what I want. Either light or dark themes.
Found basic doc. for IDLE but nothing on how to figure out what is what. Only some settings take effect.
I found all of the idlelib source in the appdata folders and put it into my project folder. I know can set the backgrounds in the IDLE shell for the various keywords etc. Looks ok for a dark theme now. When I run or compile I get the colors I set in the IDE in my text (editor) widget. I still have to set the default text colors in my app. When I don't, I get black text on white background which looks terrible in the dark theme.
So a little more work...
VSCode has syntax highlighting for the Python language. I can't find any explanation for how each token is classified and organized into colors.
Specifically, why are some keywords the same color, but some are different?
Looking at this code:
for...in shows the keywords as the same color, but if...in shows the keywords as different colors. Why does in change color? What determines if a keyword is purple or blue or something else?
Finally, is there an exhaustive list or chart for how keywords are organized?
The color of the code in VSCode is provided by the theme. (VSCode uses its own theme by default.) Reference: syntax-highlighting-optimizations and theme color.
Using different themes can make the code display different colors. You could also set the color of custom code. Reference: Customizing a Color Theme.
They are not the same in. The first is used to iterate while the second is an operator.
From the first link in #JillCheng's answer I found the Scope Inspector, which can be enabled by running Developer: Inspect Editor Tokens and Scopes in the command palette. This will then show how the currently selected text was tokenized.
for...in shows both keywords are tokenized as keyword.control.flow.python.
if...in shows if as keyword.control.flow.python and in as keyword.operator.logical.python.
Note: This answer was originally posted as part of the question.
I would like to change the Error colors in the IPython console in Spyder. Is that possible? I use Spyder 3.6 (if it matters). The error message is a mix of green and yellow... I have no know issues with my vision and I find it quite hard to read.
Here is an example:
According to this, the colors in iPython console are hardcoded and cannot be changed by Spyder itself.
One suggestion would be to switch to a dark background, so that colors like yellow are much easier to read. To do that, you can go to: Tools -> Preferences -> IPython console -> Display and click on Dark background.
Another alternative could be to use IPython %color magic to modify color scheme: https://ipython.org/ipython-doc/3/config/details.html#terminal-colors
Unfortunately, according to this, it seems as if the colour scheme cannot be changed at this moment in time.
Hopefully, the feature will be supported in future. You could try looking into a different IDE that might suit your needs.
I've recently started using PyCharm and it's autosave system is very confusing to me. Colorful tabs are even more confusing: what do the different tab color mean? There're tabs with blue text, black and red. What's the difference?
Please refer to the File Status Highlights. Tab background color can be also different depending on the Scope.
I tried (but nothing happens)
self.txt.SetBackgroundColour ((255,0,0))
As said in the title I'm trying to change the background colour StyledTextCtrl. Does anyone know a method that could be used? I've checked the API docs but I couldn't seem to find one, http://wxpython.org/docs/api/wx.stc.StyledTextCtrl-class.html
(by background colour, I mean the whole writing area, of course)
Does anyone know a way I could do this?
EDIT:
The background doesn't change in the following code
import wx
import wx.stc
app = wx.App(redirect=True)
top = wx.Frame(None, title="StyledTXTCtrl", size=(300,200))
txt=wx.stc.StyledTextCtrl(top)
txt.SetBackgroundColour((255,255,0))
txt.Refresh()
top.Show()
app.MainLoop()
My first reaction was to call txt.Refresh() because I had a similar experience using wx.TextCtrl where the background colour did not update and the Refresh() call forced a redraw. However, it seems that approach was incorrect.
After reviewing the StyledTextCtrl API, it seems like SetBackground() is not the function you want. My understanding is that because STCs can have multiple styles in the same box, the individual text styles take precedence over the STC's settings.
After some research I found the StyleSetBackground() function. This modifies the default style such that the background will be red, effectively setting the background to red. You need to call it like this:
txt.StyleSetBackground(wx.stc.STC_STYLE_DEFAULT, (255,0,0))
Just remember, if you use multiple styles you may need to make invoke this method for each one.
---EDIT---
I forgot to check my code code by entering some text. It turns out that if all you do is call SyleSetBackground() like I suggest above, when you enter text the background of the entered text is still white, not the expected red.
A bit more research and I've discoved this is easily fixed by calling the following code after setting the background colour:
txt.StyleClearAll()
My guess is that when you create the StyledTextCtrl, it sets the text style equal to wx.stc.STC_STYLE_DEFAULT. So far so good. However, after this point we change the value of the default style (by making the background red) so now the text style and the default style are different. Therefore, we need to call StyleClearAll() to reset ALL STYLES back to the default style (which now has a red background).
this works on my computer just fine
self.txt.SetBackgroundColour((255,0,0))
what is your OS?