Я хочу использовать наследование от основного и второго классов в классе Manager, но получаю < > ... пожалуйста - PullRequest
0 голосов
/ 22 февраля 2020
class Main(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.name = "main"
        self.cols = 1
        self.Main_firstISS = Button(size_hint = (0.45,0.2) , pos_hint = {'center_x': 0.5 , 'y': 0.2})
        self.Main_secISS = Button(size_hint = (0.2,0.1) , pos_hint = {'x':0.8, 'y': 0} , text = "Exit")
        self.Main_thirdISS = Label(text = "Wellcome to Guess Game\n         play and enjoy")

    self.add_widget(self.Main_firstISS)
    self.add_widget(self.Main_secISS)
    self.add_widget(self.Main_thirdISS)

class Second(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.name = "second"
        self.cols = 1
        self.Second_firstISS = TextInput(hint_text = "What's your guess" , size_hint = (0.2,0.05) , pos_hint = {'center_x':0.5 , 'y': 0.7})
        self.Second_secISS = Button(size_hint = (0.1,0.1) , pos_hint = {'x':0.9 , 'y': 0})
        self.Second_firstISS.bind(on_press=self.callback)

    self.add_widget(self.Second_firstISS)
    self.add_widget(self.Second_secISS)

def callback(self , instance):
    print(f"{self.Second_firstISS.text}")

class Manager(ScreenManager , Main , Second):
    def __init__(self , **kwargs):
        super().__init__(**kwargs)
        my_main_page = Main()
        my_second_page = Second()
        my_main_page.__init__()
        my_second_page.__init__()

Ответы [ 2 ]

0 голосов
/ 22 февраля 2020

Сначала все ваши методы инициализации неверны. И есть еще пара ошибок. Сначала вы можете попробовать исправить функции init, если это не поможет, вы можете попробовать убрать все из методов init, как здесь:

class Main(Screen):
    # if you want to redefine init function, you should do it like this
    def __init__(self, **kwargs):
        super(Main, self).__init__(**kwargs)

    # screen is using relative layout, it doesn't have cols and rows!
    # self.cols = 1
    self.Main_firstISS = Button(size_hint = (0.45,0.2) , pos_hint = {'center_x': 0.5 , 'y': 0.2})
    self.Main_secISS = Button(size_hint = (0.2,0.1) , pos_hint = {'x':0.8, 'y': 0} , text = "Exit")
    self.Main_thirdISS = Label(text = "Wellcome to Guess Game\n         play and enjoy")
    self.add_widget(self.Main_firstISS)
    self.add_widget(self.Main_secISS)
    self.add_widget(self.Main_thirdISS)

class Second(Screen):
    # same here
    def __init__(self, **kwargs):
        super(Second, self).__init__(**kwargs)

    self.Second_firstISS = TextInput(hint_text = "What's your guess" , size_hint = (0.2,0.05) , pos_hint = {'center_x':0.5 , 'y': 0.7})
    self.Second_secISS = Button(size_hint = (0.1,0.1) , pos_hint = {'x':0.9 , 'y': 0})
    self.Second_firstISS.bind(on_press=self.callback)
    self.add_widget(self.Second_firstISS)
    self.add_widget(self.Second_secISS)

    # put that function inside the class!
    def callback(self, *args):
        print(f"{self.Second_firstISS.text}")

# you don't need to inherit Main and Second classes
class Manager(ScreenManager):
    def __init__(self , **kwargs):
        # and here
        super(Manager, self).__init__(**kwargs)

    my_main_page = Main(name='main')
    my_second_page = Second(name='second')
    self.add_widget(my_main_page)
    self.add_widget(my_second_page)
0 голосов
/ 22 февраля 2020

Попробуйте

class Main(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.name = "main"
        self.cols = 1
        self.Main_firstISS = Button(size_hint = (0.45,0.2) , pos_hint = {'center_x': 0.5 , 'y': 0.2})
        self.Main_secISS = Button(size_hint = (0.2,0.1) , pos_hint = {'x':0.8, 'y': 0} , text = "Exit")
        self.Main_thirdISS = Label(text = "Wellcome to Guess Game\n         play and enjoy")

        self.add_widget(self.Main_firstISS)
        self.add_widget(self.Main_secISS)
        self.add_widget(self.Main_thirdISS)
class Second(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.name = "second"
        self.cols = 1
        self.Second_firstISS = TextInput(hint_text = "What's your guess" , size_hint = (0.2,0.05) , pos_hint = {'center_x':0.5 , 'y': 0.7})
        self.Second_secISS = Button(size_hint = (0.1,0.1) , pos_hint = {'x':0.9 , 'y': 0})
        self.Second_firstISS.bind(on_press=self.callback)

        self.add_widget(self.Second_firstISS)
        self.add_widget(self.Second_secISS)

    def callback(self , instance):
        print(f"{self.Second_firstISS.text}")

class Manager(ScreenManager):
    def __init__(self , **kwargs):
        super().__init__(**kwargs)
        my_main_page = Main()
        my_second_page = Second()
        self.add_widget(my_main_page)
        self.add_widget(my_second_page)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...