-2

最近、kivy について知りました。Pythonも最近勉強中です。入力テキスト用の2つのボックスがあり、ボタンをクリックした後に結果を含むラベルを返すkivyにしたアプリケーションが欲しいです。このコードは彼にある必要があります:


 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 に答える