gtam18
gtam18

Reputation: 1

i'm trying to make a password generater gui app using python and kivy but it doesn't work

hi i'm trying to make an app that generates a password when clicking the button "generate" using python (for the logic) and kivy(for the gui) and i think that i did everything right but when i click the genrate button ,the app stops for a bit and then return working but the text content which was originaly empty doesn't change into a random password,the box just remains empty. so guys plz help me.the python code is here:

import kivy
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import StringProperty
from kivy.uix.label import Label
from kivy.properties import ObjectProperty
import requests
import random
class float_layout(Widget):
     passw= ObjectProperty(None)
     btn = ObjectProperty(None)
     password = StringProperty("")
     def change(self,password):
      word_site = "https://www.mit.edu/~ecprice/wordlist.10000"
      signs = ["__","_","**",":","::",";",";;","&","&&","***","-","--","---","***","&&&"]
      sign = random.choice(signs)

      response = requests.get(word_site)
      WORDS = response.content.splitlines()
      number = random.randint(0,len(WORDS))
      addition1 = random.randint(0,100000)
      word= WORDS[number].decode('utf-8')+sign+str(addition1)
      word = StringProperty(word)
      
      return password == word
     
              
class GenApp(App):
     def build(self):
         return float_layout()
         
if __name__=="__main__":
     GenApp().run()

here is the kivy code:

#:kivy 1.0
<float_layout>
   passw:passw
   btn:btn
   FloatLayout:
      size: root.width,root.height
      
      TextInput:
         id:passw
         text:root.password
         size_hint:0.5,0.1
         pos_hint:{"x":0.25,"top":0.5}
         multiline:False
      Button:
         id:btn
         text:"Generate"
         size_hint:0.5,0.1
         pos_hint:{"x":0.25,"top":0.41}
         background_color:0.3, 0.5, 0.7, 1
         on_press:root.change(root.password)
            
      Image:
         source: r'C:\Users\Med\Desktop\photoshop\password_gen.png'
         pos_hint:{"x":0,"top":1.2}

here is an image of the app:
[1]: https://i.sstatic.net/Wkh22.png

Upvotes: 0

Views: 122

Answers (1)

John Anderson
John Anderson

Reputation: 38857

Just replace:

return password == word

with:

self.password = word
# return password == word

The return password == word will return either True or False depending on whether word is the same as the root.password. And the return value is not used anyway.

The text of the TextInput is already set to use whatever is in root.password, so you can just set that property.

Also, there is no need to pass in the current password value.

Upvotes: 1

Related Questions