简体   繁体   中英

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.stack.imgur.com/Wkh22.png

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM