-2

我最近才发现关于 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
'''

4

1 回答 1

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()

谢谢大家的回答;)

于 2016-03-02T12:41:48.923 回答