jeudi 23 novembre 2023

Get a Random Boolean by Percentage using tkinter

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




Aucun commentaire:

Enregistrer un commentaire