I wants to convert a string to an integer from TextBox of GUIzero.
My project is create a GUI form, from where I will grab length of a password and quantity of a password. Then I will show number of random passwords.
from guizero import App, Text, TextBox, PushButton, error
import random
# char for creating password
_chars = 'abcdefghijklmnopqrstwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.,!@#$%&'
def _say_my_name():
_welcome_message.value = "Your random value is: " + _length.value
_app = App(title="Password Creator")
message = Text(_app, text="Welcome")
_welcome_message = Text(_app, text="Create your random password here", size=19, font="Arial", color="hotpink")
#TextBox for input of password length
_length_label = Text(_app, text="Give me length of password:", size=11, font="Arial")
_length = TextBox(_app, width=33)
_length_int = int(_length.value) #THIS DOESN'T WORK
#TextBox for input of password qty: 3 pcs/ 4pcs random password
_qty_label = Text(_app, text="How many password you want: ")
_qty_of_password = TextBox(_app, width=33)
_qty_int = int(_qty_of_password.value) # THIS DOESN'T WORK
# I wants to run the code bellow to create a random password after I get password length and quantity of password.
#and print it to _welcome_message. this code works separetly.
for _p in range(_qty_of_password.value):
_password = ""
for _c in range(_length_int):
_password += random.choice(_chars)
print(_password)
# create a push button to transfer value of _my_name text box to _welcome_massage
_button = PushButton(_app, command=_say_my_name, text="Click")
_app.display()
Traceback:
Traceback (most recent call last): File "C:/Users/Owner/PycharmProjects/Assignment_2/main.py", line 18, in <module> _length_int = int(_length.value) #THIS DOESN'T WORK ValueError: invalid literal for int() with base 10: ''
Main code I got from links the below:
You set the
_length_int
,_qty_int
too early. You should attach thecommand
callback to textbox.(https://lawsie.github.io/guizero/textbox/)
Example: