Данные не доходят до MySql База данных при входе из моего GUI Киви (Python)? - PullRequest
0 голосов
/ 27 января 2020

Я получаю эту ошибку:

Файл "E: /Users/S.Urwah/GUI/venv/PyQt.py", строка 609, в add_info (self.des.text) , self.dep.text, self.cab.text, self.pas.text) AttributeError: у объекта 'NoneType' нет атрибута 'text'

Основная проблема, которую я получаю, - это когда я ввожу данные на предоставленной строке ввода текста на моем GUI, она не достигает моих MySql таблиц базы данных .. я создал 4 таблицы для этих 4 экранов, ввод формы данных, а именно: бронирование, статус рейса, информация о рейсе и расписания .. я создаю Система управления полетами, так что просим вас подробно ознакомиться с этой проблемой ..

Код:

from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.lang import Builder
from kivy.properties import StringProperty
from kivy.properties import ObjectProperty
from kivy.uix.gridlayout import GridLayout
#from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.widget import Widget
from kivy.core.image import Image
#from kivy.graphics import BorderImage
from kivy.graphics import Color, Rectangle
#from kivy.uix.image import AsyncImage
import mysql.connector


kv_str = """
MyScreenManager:

    BRANCH:
        name: 'branch'
    S1:
        name: 'Flight Info'
    S2:
        name: 'Schedules'
    S3:
        name: 'Flight Status'
    S4:
        name: 'My Booking'    
    FINAL_SCREEN1:
        id: final
        name: 'final_screen1'
    FINAL_SCREEN2:
        id: final
        name: 'final_screen2'    
    FINAL_SCREEN3:
        id: final
        name: 'final_screen3'
    FINAL_SCREEN4:
        id: final
        name: 'final_screen4'        


<BRANCH>    
    FloatLayout:
        orientation: 'horizontal'
        canvas:
            Rectangle:
                source: 'E:/Users/S.Urwah/GUI/venv/Jet.png'
                size: self.size
                pos: self.pos
        Label:
            pos_hint: {'x': 0.00, 'y': 0.40}
            font_size: 45
            text: 'Air Fly'
            color: 0 ,0, 0, 1

        Label:
            pos_hint: {'x': 0.00, 'y': 0.30}
            font_size: 35
            text: 'Come Fly with us'
            color: 0, 0, 0, 1
        Label:
            pos_hint: {'x': 0.00, 'y': 0.35}
            font_size: 45
            text: '-----------'
            color: 0 ,0, 0, 1

        Label:
            pos_hint: {'x': 0.00, 'y': 0.25}
            font_size: 35
            text: '---------------------------'
            color: 0, 0, 0, 1

        Button:
            text: 'Flight Info'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: { 'x': 0.20, 'y': 0.40}
            on_release:
                root.manager.transition.direction = 'right'
                root.manager.current = 'Flight Info'
        Button:
            text: 'Schedules'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.50, 'y': 0.40}
            on_release:
                root.manager.transition.direction = 'left'
                root.manager.current = 'Schedules'
        Button:
            text: 'Flight Status'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.20, 'y': 0.60}
            on_release:
                root.manager.transition.direction = 'right'
                root.manager.current = 'Flight Status'
        Button:
            text: 'My Booking'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.50, 'y': 0.60}
            on_release:
                root.manager.transition.direction = 'left'
                root.manager.current = 'My Booking'
<S1>:
    FloatLayout:
        orientation: 'horizontal'
        canvas:
            Rectangle:
                source: 'E:/Users/S.Urwah/GUI/venv/s1.jpg'
                size: self.size
                pos: self.pos


        Label:
            pos_hint: {'x': 0.00, 'y': 0.40}
            font_size: 40
            text: 'FLIGHT INFO'
            color: 0, 0, 0, 1

        Label:
            pos_hint: {'x': 0.00, 'y': 0.35}
            font_size: 45
            text: '----------------'
            color: 0 ,0, 0, 1

        AnchorLayout:
            anchor_x: 'center'
            anchor_y: 'center'

            BoxLayout:
                orientation: 'vertical'
                width: 300
                size_hint: None, None
                TextInput:

                    multiline: False
                    hint_text: 'Destination'
                    size_hint: None, None
                    width: 300
                    height: 32
                TextInput:
                    multiline: False
                    hint_text: 'Departure '
                    size_hint: None, None
                    width: 300
                    height: 32
                TextInput:
                    multiline: False
                    hint_text: 'Cabin'
                    size_hint: None, None
                    width: 300
                    height: 32
                TextInput:
                    multiline: False
                    hint_text: 'Passenger'
                    size_hint: None, None
                    width: 300
                    height: 32



        Button:
            text: 'BACK'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.20, 'y': 0.15}
            on_release:
                root.manager.transition.direction = 'left'
                root.manager.current = 'branch'
                root.manager.ids.final.previous = root.name

        Button:
            text: 'SUBMIT'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.60, 'y': 0.15}
            on_release:
                root.add_info()
                root.manager.transition.direction = 'right'
                root.manager.current = 'final_screen1'


<S2>:
    FloatLayout:
        orientation: 'horizontal'
        canvas:
            Rectangle:
                source: 'E:/Users/S.Urwah/GUI/venv/s2.jpg'
                size: self.size
                pos: self.pos

        Label:
            pos_hint: {'x': 0.00, 'y': 0.20}
            font_size: 40
            text: 'SCHEDULES'
            color: 0, 0, 0, 1

        Label:
            pos_hint: {'x': 0.00, 'y': 0.15}
            font_size: 45
            text: '-------------------'
            color: 0 ,0, 0, 1

        AnchorLayout:
            anchor_x: 'center'
            anchor_y: 'center'

            BoxLayout:
                orientation: 'vertical'
                width: 300
                size_hint: None, None
                TextInput:
                    multiline: False
                    hint_text: 'Destination'
                    size_hint: None, None
                    width: 300
                    height: 32
                TextInput:
                    multiline: False
                    hint_text: 'Date '
                    size_hint: None, None
                    width: 300
                    height: 32



        Button:
            text: 'BACK'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.20, 'y': 0.15}
            on_release:
                root.manager.transition.direction = 'right'
                root.manager.current = 'branch'
                root.manager.ids.final.previous = root.name
        Button:
            text: 'SUBMIT'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.60, 'y': 0.15}

            on_release:
                root.add_info()
                root.manager.transition.direction = 'left'
                root.manager.current = 'final_screen2'


<S3>:
    FloatLayout:
        orientation: 'horizontal'
        canvas:
            Rectangle:
                source: 'E:/Users/S.Urwah/GUI/venv/s3.jpg'
                size: self.size
                pos: self.pos

        Label:
            pos_hint: {'x': 0.00, 'y': 0.15}
            font_size: 45
            text: '-----------------------'
            color: 1,1,1, 1

        Label:
            pos_hint: {'x': 0.00, 'y': 0.20}
            font_size: 40
            text: 'FLIGHT STATUS'
            color: 1, 1, 1, 1
        AnchorLayout:
            anchor_x: 'center'
            anchor_y: 'center'

            BoxLayout:
                orientation: 'vertical'
                width: 300
                size_hint: None, None
                TextInput:
                    multiline: False
                    hint_text: 'Destination Date'
                    size_hint: None, None
                    width: 300
                    height: 32
                TextInput:
                    multiline: False
                    hint_text: 'Departure Date '
                    size_hint: None, None
                    width: 300
                    height: 32

        Button:
            text: 'BACK'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.20, 'y': 0.15}
            on_release:
                root.manager.transition.direction = 'left'
                root.manager.current = 'branch'
                root.manager.ids.final.previous = root.name
        Button:
            text: 'SUBMIT'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.60, 'y': 0.15}
            on_release:
                root.add_info()
                root.manager.transition.direction = 'right'
                root.manager.current = 'final_screen3'

<S4>:
    FloatLayout:
        orientation: 'horizontal'
        canvas:
            Rectangle:
                source: 'E:/Users/S.Urwah/GUI/venv/s4.jpg'
                size: self.size
                pos: self.pos

        Label:
            pos_hint: {'x': 0.00, 'y': 0.20}
            font_size: 40
            text: 'BOOKING'
            color: 0, 0, 0, 1
        Label:
            pos_hint: {'x': 0.00, 'y': 0.15}
            font_size: 45
            text: '-----------------'
            color: 0 ,0, 0, 1

        AnchorLayout:
            anchor_x: 'center'
            anchor_y: 'center'

            BoxLayout:
                orientation: 'vertical'
                width: 300
                size_hint: None, None
                TextInput:
                    multiline: False
                    hint_text: 'Destination'
                    size_hint: None, None
                    width: 300
                    height: 32
                TextInput:
                    multiline: False
                    hint_text: 'Time'
                    size_hint: None, None
                    width: 300
                    height: 32
                TextInput:
                    multiline: False
                    hint_text: 'Ticket Price'
                    size_hint: None, None
                    width: 300
                    height: 32    

        Button:
            text: 'BACK'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.20, 'y': 0.15}
            on_release:
                root.manager.transition.direction = 'right'
                root.manager.current = 'branch'
                root.manager.ids.final.previous = root.name
        Button:
            text: 'SUBMIT'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.60, 'y': 0.15}

            on_release:
                root.add_info()
                root.manager.transition.direction = 'left'
                root.manager.current = 'final_screen4'

<FINAL_SCREEN1>:
    FloatLayout:
        orientation: 'horizontal'
        canvas:
            Rectangle:
                source: 'E:/Users/S.Urwah/GUI/venv/fs.jpg'
                size: self.size
                pos: self.pos

        Label:
            pos_hint: {'x': 0.00, 'y': 0.40}
            font_size: 40
            text: 'FLIGHT INFO'
            color: 0, 0, 0, 1
        Label:
            pos_hint: {'x': 0.00, 'y': 0.35}
            font_size: 45
            text: '-----------------'
            color: 0 ,0, 0, 1




        Button:
            text: 'BACK'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.20, 'y': 0.15}
            on_release:
                root.manager.transition.direction = 'right'
                root.manager.current = 'branch'
                root.manager.ids.final.previous = root.name
        Button:
            text: 'EXIT'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.60, 'y': 0.15}
            on_release:
                root.manager.transition.direction = 'right'
                root.manager.current = root.previous
<FINAL_SCREEN2>:
    FloatLayout:
        orientation: 'horizontal'
        canvas:
            Rectangle:
                source: 'E:/Users/S.Urwah/GUI/venv/fs.jpg'
                size: self.size
                pos: self.pos

        Label:
            pos_hint: {'x': 0.00, 'y': 0.40}
            font_size: 40
            text: 'SCHEDULES'
            color: 0, 0, 0, 1
        Label:
            pos_hint: {'x': 0.00, 'y': 0.35}
            font_size: 45
            text: '-----------------'
            color: 0 ,0, 0, 1




        Button:
            text: 'BACK'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.20, 'y': 0.15}
            on_release:
                root.manager.transition.direction = 'right'
                root.manager.current = 'branch'
                root.manager.ids.final.previous = root.name
        Button:
            text: 'EXIT'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
`           size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.60, 'y': 0.15}
            on_release:
                root.manager.transition.direction = 'right'
                root.manager.current = root.previous                                

<FINAL_SCREEN3>:
    FloatLayout:
        orientation: 'horizontal'
        canvas:
            Rectangle:
                source: 'E:/Users/S.Urwah/GUI/venv/fs.jpg'
                size: self.size
                pos: self.pos

        Label:
            pos_hint: {'x': 0.00, 'y': 0.40}
            font_size: 40
            text: 'FLIGHT STATUS'
            color: 0, 0, 0, 1
        Label:
            pos_hint: {'x': 0.00, 'y': 0.35}
            font_size: 45
            text: '-----------------'
            color: 0 ,0, 0, 1




        Button:
            text: 'BACK'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.20, 'y': 0.15}
            on_release:
                root.manager.transition.direction = 'right'
                root.manager.current = 'branch'
                root.manager.ids.final.previous = root.name
        Button:
            text: 'EXIT'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.60, 'y': 0.15}
            on_release:
                root.manager.transition.direction = 'right'
                root.manager.current = root.previous
<FINAL_SCREEN4>:
    FloatLayout:
        orientation: 'horizontal'
        canvas:
            Rectangle:
                source: 'E:/Users/S.Urwah/GUI/venv/fs.jpg'
                size: self.size
                pos: self.pos

        Label:
            pos_hint: {'x': 0.00, 'y': 0.40}
            font_size: 40
            text: 'BOOKING'
            color: 0, 0, 0, 1
        Label:
            pos_hint: {'x': 0.00, 'y': 0.35}
            font_size: 45
            text: '-----------------'
            color: 0 ,0, 0, 1




        Button:
            text: 'BACK'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.20, 'y': 0.15}
            on_release:
                root.manager.transition.direction = 'right'
                root.manager.current = 'branch'
                root.manager.ids.final.previous = root.name
        Button:
            text: 'EXIT'
            color: 1.0, 0.6, 0.0, 1
            font_size: 20
            size_hint_x: 0.25
            size_hint_y: 0.10
            pos_hint: {'x': 0.60, 'y': 0.15}
            on_release:
                root.manager.transition.direction = 'right'
                root.manager.current = root.previous
"""

class MyScreenManager(ScreenManager):
    pass

# Branch Screen, takes you to S1, S2, or S3

class BRANCH(Screen):
    pass


class S1(Screen):
    id = ObjectProperty(None)
    des = ObjectProperty(None)
    dep = ObjectProperty(None)
    cab = ObjectProperty(None)
    pas = ObjectProperty(None)
    def add_info(self):
        mydb = mysql.connector.connect(
            host='localhost',
            username='root',
            passwd='',
            database='db_of_flightsystem'
        )

        cur = mydb.cursor()
        table = """INSERT INTO Flight_Info (fl_id, DESTINATION, DEPARTURE, CABIN, PASSENGER) VALUES (?,?,?,?,?)""",\
                (self.des.text ,self.dep.text ,self.cab.text ,self.pas.text)
        cur.execute(table)
        mydb.commit()
        mydb.close()


class S2(Screen):
    id = ObjectProperty(None)
    sts = ObjectProperty(None)
    inf = ObjectProperty(None)

    def add_info(self):
        mydb = mysql.connector.connect(
            host='localhost',
            username='root',
            passwd='',
            database='db_of_flightsystem'
        )

        cur = mydb.cursor()
        table = """INSERT INTO Schedules (fl_sd, Flight_Status, Flight_Info) VALUES (?,?,?)""", \
                ( self.sts.text, self.inf.text )
        cur.execute(table)
        mydb.commit()
        mydb.close()

class S3(Screen):
    id = ObjectProperty(None)
    ap = ObjectProperty(None)
    time = ObjectProperty(None)
    depd = ObjectProperty(None)
    avd = ObjectProperty(None)
    des = ObjectProperty(None)

    def add_info(self):
        mydb = mysql.connector.connect(
            host='localhost',
            username='root',
            passwd='',
            database='db_of_flightsystem'
        )

        cur = mydb.cursor()
        table = """INSERT INTO Flight_Status (fl_st, ARRIVAL_PLACE, TIME, DEPARTURE_DATE, ARRIVAL_DATE, DESTINATION) " \
                "VALUES  (?,?,?,?,?,?)""", \
                ( self.ap.text, self.time.text, self.depd.text, self.des.text)
        cur.execute(table)
        mydb.commit()
        mydb.close()


class S4(Screen):
    id = ObjectProperty(None)
    des = ObjectProperty(None)
    dep = ObjectProperty(None)
    cab = ObjectProperty(None)
    pas = ObjectProperty(None)

    def add_info(self):
        mydb = mysql.connector.connect(
            host='localhost',
            username='root',
            passwd='',
            database='db_of_flightsystem'
        )

        cur = mydb.cursor()
        table = """INSERT INTO Booking (book_id, TIME, Ticket_Price, DESTINATION) VALUES (?,?,?,?)""", \
                ( self.des.text, self.dep.text, self.cab.text, self.pas.text)
        cur.execute(table)
        mydb.commit()
        mydb.close()


class FINAL_SCREEN1(Screen):
    previous = StringProperty()
class FINAL_SCREEN2(Screen):
    previous = StringProperty()
class FINAL_SCREEN3(Screen):
    previous = StringProperty()
class FINAL_SCREEN4(Screen):
    previous = StringProperty()

class AirFly(App):
    def build(self):
        return Builder.load_string(kv_str)


    mydb = mysql.connector.connect(
        host='localhost',
        username='root',
        passwd='',
        database='db_of_flightsystem'
    )

    cur = mydb.cursor()

    cur.execute(""" CREATE TABLE IF NOT EXISTS Flight_Info(
                fl_id INT NOT NULL AUTO_INCREMENT, DESTINATION text,
                 DEPARTURE text, CABIN text , PASSENGER text,
                 PRIMARY KEY (fl_id))
                """)

    cur.execute(""" CREATE TABLE IF NOT EXISTS Flight_Status(
                fl_st INT NOT NULL AUTO_INCREMENT, ARRIVAL_PLACE text,
                 TIME text, DEPARTURE_DATE text, ARRIVAL_DATE text, DESTINATION text,
                 PRIMARY KEY (fl_st))
                """)
    cur.execute(""" CREATE TABLE IF NOT EXISTS Schedules(
                fl_sd INT NOT NULL AUTO_INCREMENT, Flight_Status text, Flight_Info text,
                PRIMARY KEY (fl_sd))
                """)
    cur.execute(""" CREATE TABLE IF NOT EXISTS Booking(book_id INT NOT NULL AUTO_INCREMENT, TIME text, Ticket_Price text,
                DESTINATION text,PRIMARY KEY (book_id))
               """)

    mydb.commit()
    mydb.close()

if __name__ == '__main__':
    AirFly().run()
...