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

Jen Farrant
Jen Farrant
6,905 Points

the clear screen doesn't work.

I cannot get the clear screen function to work. I'm on a mac, and I've tried it the code in Idle and Thonny. It's not my code that's the issue, I've downloaded Kenny's code (which I presume works fine!) and I can't get that to work in Thonny or Idle either.

It's not just this section of the course, it is anytime that I use the clear function - it just doesn't work. I'm using the code for both mac and windows in my coding.

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

and as I said, even Kenny's code doesn't work, so I'm confident I haven't made an error

Any suggestions?

2 Answers

Viraj Deshaval
Viraj Deshaval
4,874 Points

It will not work in IDLE or Thonny or any other python work ground because "os" library let's us use functionality on operating system level. To perform similar kind of thing in IDLE you can try this as below:

def clear(): print("\n" * 150) clear() print("Hello Treehouse")```

I hope I answered your query. Please let me know if you require any example.

Jen Farrant
Jen Farrant
6,905 Points

I did not know that.... thank you for letting me know, I can stop being extremely frustrated now!

Viraj Deshaval
Viraj Deshaval
4,874 Points

Hi Jen, Thanks for reaching out to community. You need to import os module in order to use os functions. Just write "import os" without quotes of course and try it should work.

Jen Farrant
Jen Farrant
6,905 Points

sorry, should have been clearer - I'm already doing that further up the screen