-2

I am coding a calculator. I decided to use 2 strings, one that is shown to the user on a screen, and one, that is for making the calculation. I now want to make a function that deletes everything on the screen. But now I have the problem, that the variable, that is used to perform the calculation, still has the value of the number inside of it. I wanted to ask, how I could remove that number. I also use a tkinter window, to show everything.

Here is the function, where I wanted to do that:

def clear_S(event):
    global Evaluation_T    #This gets shown
    global Evaluation_C    #This is for the calculation
    Evaluation_T = "                "
    renew_Label()          #Displays it to a 
    Evaluation_T = ""
    #Logic, to remove that from Evaluation_C

If you need any more information, please ask.

1 Answers1

0

It's not how input and output work. When you print something, you print the value of that variable on STDOUT which is a stream file to connect your software with your terminal. What you're doing it like do a photocopy and edit the original copy expecting that the photocopy will be edited too. Have a look at Is there a way to clear your printed text in python? it should be what you were looking for.

EDIT: I misunderstand what you asked. There are different solutions: 1) If Evaluation_Text is always the end of Evaluation_C you can do:

Evaluation_C = Evaluation_C[:-len(Evaluation_Text)]

or

2) You can use replace with reverse string and do it only one time with:

Evaluation_C[::-1].replace(Evaluation_Text[::-1], 1)

  • I don't want to remove it from the console, I want to remove the string from my program. Like, let's say, Evaluation_Text = "398" and Evaluation_C = "999+398", then i want to remove the 398 from both, so that Evaluation_C = "999+". I also want to do it only one, so that Evaluation C = "30+30" doesn't get completely removed. And i don't know i should do that, but wan't an easy solution, so I don't have to do new if-statements, if I want to add something.. – Artemis_Fowl44HD Apr 02 '20 at 10:57