Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Letter Game App Letter Game Refinement

Cannot clear screen

In the "Letter Game Refinement" segment a clear function is defined that is used to clear the screen in order to keep it tidy. I tried this code in IDLE and instead of clearing my screen it opened a shell window for a split second and then closed it (assume it was the python shell but could have been cmd). My IDLE screen remained unchanged. Is it possible that os.system('clear') does not work the same way in IDLE as shown in the video? Or do I have a silly mistake in the code? Many thanks.

def clear():
         if os.name == 'nt':
             os.system('cls')
         else:
             os.system('clear')

2 Answers

I believe you are correct. The above function can clear the console/terminal but in IDLE it will not work. Here is a stackoverflow question about this http://stackoverflow.com/questions/1432480/any-way-to-clear-pythons-idle-window#1433818.

Beshoy Megalaa
Beshoy Megalaa
3,429 Points

os.system('cls')/os.system('clear') only work in terminal/console and not idle.