我无法理解如何将我的代码转化为kivy

时间:2016-02-29 22:28:35

标签: android python kivy buildozer

我最近刚刚发现了kivy。 Python我最近也在研究。我想要应用程序,制作为kivy,它有2个输入文本框,并在单击按钮后返回带有结果的标签。这段代码必须在他身上:

 def word_detect(a,b):
     y = []
     e = []
     s = []
     for counter in range(len(b)):
          z = []
          for word in a:
               ml = 0
               index = -1
               for letter in word:
                    index += 1
                    if letter == (b[counter])[index]:
                         ml += 1
               if ml == int((b[counter])[-1]):
                    z.append(word)
          y.append(z)
          e.extend(z)
     for i in e:
          if (y[0]).count(i)==(y[1]).count(i)==(y[2]).count(i)==1 and s.count(i)==0:
              s.append(i)
     return s

 print word_detect(raw_input('list:   '). upper().  split(','),raw_input('words:  '). upper(). split(','))
'''
e.g:
list : total,relax,mixer,remix,scope,candy,water
words: helix 3, botex 1, below 2

result: ['relax']

RELAX
hELiX - 3 matched letters
boteX - 1 matched letter
bELow - 2 matched letters
'''

1 个答案:

答案 0 :(得分:0)

我做到了!如果其他人有类似的问题,例如,我是如何决定的:

  from kivy.app import App
  from kivy.uix.textinput import TextInput
  from kivy.uix.label import Label
  from kivy.uix.boxlayout import BoxLayout
  from kivy.uix.button import Button

  class Vzlom_App(App):
      def word_detect(self,value):
           a = str(self.wdlist.text).upper(). split(',')
           b = str(self.wd.text).upper(). split(',')
           y = []
           e = []
           s = []
           for counter in range(len(b)):
                z = []
                for word in a:
                     ml = 0
                     index = -1
                     for letter in word:
                          index += 1
                          if letter == (b[counter])[index]:
                               ml += 1
                     if ml == int((b[counter])[-1]):
                          z.append(word)
                y.append(z)
                e.extend(z)
           for i in e:
                if (y[0]).count(i)==(y[1]).count(i)==(y[2]).count(i)==1 and s.count(i)==0:
                     s.append(i)
           self.lab.text = str(s)

      def build(self):
           window = BoxLayout(orientation='vertical')
           self.btn = Button(text='OK',font_size=50,size_hint_y=None,height=80)
           self.lab = Label(text="",font_size=70) 
           self.wdlist = TextInput(multiline=False,font_size=50,size_hint_y=None,height=250)
           self.wd = TextInput(multiline=False,font_size=50,size_hint_y=None,height=80)
           self.btn.bind(on_press=self.word_detect)
           window.add_widget(self.wd)
           window.add_widget(self.wdlist)
           window.add_widget(self.lab)
           window.add_widget(self.btn)
           return window

  if __name__ == "__main__":
           Vzlom_App().run()

感谢大家的回答;)