Python Forum
Clearing IDLE of text and homing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clearing IDLE of text and homing
#1
I used to enjoy writing games using BASIC way back in the day. I tried searching the forums but did not find an answer. Wondering if Python has a program command that will both clear the shell of text and home the cursor so that the next desired text will start displaying from the upper left corner?
Right now I am just tinkering with some text based game ideas. I came up with this simple card handling routine. Eventually I want to branch out into a text adventure idea. (I wrote a text adventure type game on my old computer back in the 80's in BASIC).

My card handling scheme so far is listed below. (But wondering about the clear IDLE and homing cursor for a prettier display.)

from random import *
# best results rifling should be <= 1/2 number of list elements

cards=[]
suitname=['Clubs','Diamonds','Spades','Hearts']
facename=[2,3,4,5,6,7,8,9,10,'J','Q','K','A']
for fill in range(0,52):
    cards.append(fill)
 
print("      Unshuffled: ",cards,"\n")

for rifling in range(1,4):
     shuffle(cards)
     print("After",rifling,"shuffles: ",cards)

pick=randint(0,52)

suit=pick//13
face=pick%13

print("You pulled the",facename[face],"of",suitname[suit])
Reply
#2
You can import the os module and clear the screen that way. However, the IDLE screen won't clear the way you want it too. You would have to learn how to run python programs in the Comand Prompt(Assuming you're using Windows) here's a skeleton for clearing the screen

import os

if __name__ == 'main':

    # Prints before clear screen
    print("Here's some text.")

    # Clears the screen
    os.system("CLS")

    # Prints after clear screen
    print("Screen cleared!")
Also, please don't use import _______ from *. Its really bad practice in python. Instead just use import random
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Clearing an asyncio queue if it's empty H84Gabor 0 1,769 Jan-28-2022, 02:27 AM
Last Post: H84Gabor
  IDLE not importing pygame (ok outside of IDLE) miner_tom 1 3,282 Sep-14-2018, 07:54 PM
Last Post: Larz60+
  Python IDLE 3.6.2 on WIn7 vs Pyhton 3 IDLE raspberry djdan_23 5 5,653 Sep-07-2017, 12:51 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020