Posts: 26
Threads: 7
Joined: Sep 2022
Nov-20-2022, 12:50 PM
(This post was last modified: Nov-20-2022, 02:52 PM by BliepMonster.)
I was trying to make it so that it wrote the variable 'hp' in red.
import sys
color = sys.stdout.shell
hp = 100
color.write(hp, 'COMMENT') Got this error.
Error: Traceback (most recent call last):
File "C:\Users\Wannes\survivalor 1.6 The Combat Update Klad.py", line 406, in <module>
color.write(hp, 'COMMENT')
AssertionError
I am using the IDLE. What is wrong?
Should I just use 'print' for variables and 'color.write' for anything else? Or can this be fixed?
(Any onther method for color, like ANSI, colorama, or colored doesn't work in IDLE, on my computer)
The only stupid person in the world, is the person that doesn't ask questions.
-Someone smart
Posts: 12,030
Threads: 485
Joined: Sep 2016
see this post which uses 'rich' package for colorizing text https://python-forum.io/thread-38602-pos...#pid163693
Posts: 26
Threads: 7
Joined: Sep 2022
(Nov-20-2022, 02:52 PM)Larz60+ Wrote: see this post which uses 'rich' package for colorizing text https://python-forum.io/thread-38602-pos...#pid163693
Does that work in IDLE? Because anything for color except sys doesn't work on IDLE, as far as I know.
The only stupid person in the world, is the person that doesn't ask questions.
-Someone smart
Posts: 12,030
Threads: 485
Joined: Sep 2016
Quote:Does that work in IDLE? Because anything for color except sys doesn't work on IDLE, as far as I know.
My opinion:
Get rid of IDLE and pick a real IDE.
Even though IDLE is packaged with python, it's not a good, nor in my opinion a real IDE.
VSCode is very good and used by many on this forum, as is PyCharm
to install VSCode see: https://python-forum.io/thread-12237.html
Posts: 26
Threads: 7
Joined: Sep 2022
Nov-20-2022, 05:19 PM
(This post was last modified: Nov-20-2022, 05:50 PM by BliepMonster.)
(Nov-20-2022, 03:09 PM)Larz60+ Wrote: Quote:Does that work in IDLE? Because anything for color except sys doesn't work on IDLE, as far as I know.
My opinion:
Get rid of IDLE and pick a real IDE.
Even though IDLE is packaged with python, it's not a good, nor in my opinion a real IDE.
VSCode is very good and used by many on this forum, as is PyCharm
to install VSCode see: https://python-forum.io/thread-12237.html I will not download anything else. I already have enough downloads everyone tells me to get and I barely use them. Also, IDLE is a completely functional IDE and I will not get rid of it. I don't care what your opinion is on IDLE. Did I ask?
I already found a solution, so I won't use 'Rich' or anything else.
The only stupid person in the world, is the person that doesn't ask questions.
-Someone smart
Posts: 453
Threads: 16
Joined: Jun 2022
Nov-20-2022, 06:13 PM
(This post was last modified: Nov-20-2022, 06:15 PM by rob101.)
Larz60 Wrote:My opinion:
Get rid of IDLE and pick a real IDE.
Even though IDLE is packaged with python, it's not a good, nor in my opinion a real IDE.
VSCode is very good and used by many on this forum, as is PyCharm
to install VSCode see: https://python-forum.io/thread-12237.html
You can also get the Free/Libre Open Source Software Binaries of VS Code. I've not yet tried this, as I've been using the an different IDE, but for anyone else that may be interested (the thread OP clearly is not).
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Posts: 4,787
Threads: 76
Joined: Jan 2018
Nov-20-2022, 07:04 PM
(This post was last modified: Nov-20-2022, 07:04 PM by Gribouillis.)
(Nov-20-2022, 05:19 PM)BliepMonster Wrote: I already found a solution, so I won't use 'Rich' or anything else. Can you share your solution to print with colors in the IDLE IDE?
buran and rob101 like this post
Posts: 26
Threads: 7
Joined: Sep 2022
Nov-21-2022, 12:24 PM
(This post was last modified: Nov-21-2022, 12:24 PM by BliepMonster.)
(Nov-20-2022, 07:04 PM)Gribouillis Wrote: (Nov-20-2022, 05:19 PM)BliepMonster Wrote: I already found a solution, so I won't use 'Rich' or anything else. Can you share your solution to print with colors in the IDLE IDE?
The solution to printing text:
import sys
color = sys.stdout.shell
color.write('Anything you want', 'STRING')
color.write('can go here\n', 'STRING')
color.write('Just remember to end the line with the \\n', 'STRING') Output: Anything you want can go here
Just remember to end the line with the \n
(In the string color)
Now, this doesn't work for variables. For that, you can just use print() with end=' ' to keep it on the same line. It isn't as good as color, but it works.
import sys
color = sys.stdout.shell
color.write('This', 'STRING')
print('Is on the same line', end = ' ')
color.write('As this', 'STRING')
Gribouillis likes this post
The only stupid person in the world, is the person that doesn't ask questions.
-Someone smart
Posts: 4,787
Threads: 76
Joined: Jan 2018
Nov-21-2022, 04:24 PM
(This post was last modified: Nov-21-2022, 04:24 PM by Gribouillis.)
This is interesting, it actually works to write text in green, blue or red and other colors of the syntax highlighting configuration. The underlying mechanism is the one that allows to print in colors in a Tkinter text window. Perhaps it could be possible to modify the code to print in any color in IDLE. It seems that a lot of the magic happens in the file colorizer.py of idlelib.
Nice idea, however there are not so many applications. Printing in color in a console is often an unnecessary gadget that just makes your code more complex.
Posts: 6,794
Threads: 20
Joined: Feb 2020
The main problem I have with IDLE, other than it having a terrible editor, is that many programs run differently when run in IDLE. If you only ever run your programs from an IDE and the IDE is always IDLE that is not a problem, but that is quite a limitation.
|