输入错误密码后试图弹出弹出窗口

时间:2018-07-21 22:40:59

标签: python-2.7 kivy kivy-language

当我输入正确的密码时,它会执行我想要的操作,然后转到下一个屏幕。当我输入错误的密码时,它不会像我想要的那样进入下一个屏幕,但是,当应该出现弹出窗口时,它将引发错误。

这是应用代码:

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.clock import mainthread
from kivy.uix.button import Button
from kivy.uix.popup import Popup



Builder.load_file('main.kv')


class Menu(BoxLayout):
   manager = ObjectProperty(None)


class ScreenLogIn(Screen):

  @mainthread
  def verify_credentials(self):

    try:


        if self.ids.login.text == "email@email.com" and self.ids.passw.text == "password":
            self.manager.current = "match"
        else:
            popup = Popup(title='Wrong',
                          content='Wrong Email/Password')
            popup.open()
    except Exception as e:
        pass


class ScreenNearUsers(Screen):

    @mainthread
    def on_enter(self):
      for i in xrange(101):
          button = Button(text="B_" + str(i))
          self.ids.grid.add_widget(button)


class ScreenMatch(Screen):
   pass


class ScreenChats(Screen):
   pass


class ScreenUserProfile(Screen):
  pass


class Manager(ScreenManager):
    screen_log_in = ObjectProperty(None)
    screen_near_user = ObjectProperty(None)
    screen_match = ObjectProperty(None)
    screen_chats = ObjectProperty(None)
    screen_user_profile = ObjectProperty(None)


class MenuApp(App):

   def build(self):
      return Menu()


if __name__ == '__main__':
    MenuApp().run()`   

main.kv:

#get login screen working
<Menu>:
   manager: screen_manager
   orientation: "vertical"
   id: action
   ActionBar:
       size_hint_y: 0.1
       background_color: 0, 0, 35, 2
       background_normal: ""
       ActionView:
           ActionPrevious:
           ActionButton:
                id: near_users
                icon: 'icons/internet.png'
                on_press: root.manager.current = 'near_users'
           ActionButton:
               id: matching
               text: "Matching"
               on_press: root.manager.current= 'match'
           ActionButton:
               id: chat
               text: "chat"
               on_press: root.manager.current = 'chats'
           ActionButton:
               id: profile
               text: "Profile"
               on_press: root.manager.current = 'profile'
   Manager:
      id: screen_manager

<ScreenLogIn>:
    orientation: "horizontal"
    id: login_screen
    BoxLayout:
        TextInput:
            id: login
        TextInput:
            id: passw
            password: True # hide password
        Button:
            text: "Log In"
            on_release: root.verify_credentials()

<ScreenNearUsers>:
     ScrollView:
         GridLayout:
            id: grid
            size_hint_y: None
            height: self.minimum_height
            cols: 2
            row_default_height: '20dp'
            row_force_default: True
            spacing: 0, 0
            padding: 0, 0

<ScreenMatch>:
    Button:
        text:
<ScreenChats>:
    Button:
        text: "stuff3"
<ScreenUserProfile>:
    Button:
        text: "stuff4"

<Manager>:
    id: screen_manager
    screen_log_in: screen_log_in
    screen_near_users: screen_near_users
    screen_match: screen_match
    screen_chats: screen_chats
    screen_user_profile: screen_user_profile

ScreenLogIn:
    id: screen_log_in
    name: 'login'
    manager: screen_manager
ScreenNearUsers:
    id: screen_near_users
    name: 'near_users'
    manager: screen_manager
ScreenMatch:
    id: screen_match
    name: 'match'
    manager: screen_manager
ScreenChats:
    id: screen_chats
    name: 'chats'
    manager: screen_manager
ScreenUserProfile:
    id: screen_user_profile
    name: 'profile'
    manger: screen_manager

错误:

  

[WARNING]没有设置列或行,不会触发布局。

0 个答案:

没有答案