0

Please could you explain how to use tkinter to make an Entry widget that passes a percentage value to the function below e.g. the user enters 60 into the input field which then passes the user’s value to the percent = 55 argument so it updates in real time to whatever value the user types in?

def reset(percent=55):
    prob = random.randrange(0,100)
    if prob > percent:
        return True
    else:
        return False
    
print(reset(15)) 

N.B Matplotlib, random and NumPy are being imported.

Tried using the input(), int() and str() functions but the IDLE still produces errors. Editing the 'percent=' argument too much causes the program to crash.

The 'percent=' argument only seems to accept the format: percent=number

4
  • can u put the error in the question? Commented Nov 23, 2023 at 18:05
  • There seems to be an indentation problem in the code you posted. Commented Nov 23, 2023 at 18:39
  • Your code is working on Python 3.12.0rc3.
    – user4136999
    Commented Nov 23, 2023 at 19:28
  • Is the problem that the code runs reset("60") not reset(60), passing a sting not a numeric? If it is, there needs to be a function that converts anything the user can enter into the Entry into an acceptable int before passing it to reset.
    – Tls Chris
    Commented Nov 23, 2023 at 21:47

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.