Как добавить класс с родителем StackLayout в другой layout?
У меня есть модульный проект на PyQt5, в качестве тренировки, я решил перенести его на kivy.
Есть файл в котором есть код (ещё в разработке):
from os.path import abspath, basename
import sys
from kivy.app import App
from kivy.config import Config
Config.set('graphics', 'width', '550')
Config.set('graphics', 'height', '550')
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.stacklayout import StackLayout
from kivy.uix.image import Image
from kivy.lang import Builder
File_location = str(abspath(__file__)).replace(str(basename(__file__)),'')
class Player_1(StackLayout):
global File_location
File_loc = File_location
font_loc = File_location + 'arial_black.ttf'
def __init__(self):
super(Player_1, self).__init__()
self.label_inf = Label(text='Тест')
self.add_widget(self.label_inf)
class StartApp(App):
def build(self):
Builder.load_file('player_1_design.kv')
return Player_1()
player_1_design.kv:
<Player_1>:
spacing: 5
padding: 2
Image:
sourse: root.File_loc + 'polzovatel_1.png'
size_hint: 1,0.3
Button:
text: 'Валюта'
size_hint: 0.30, 0.07
pos_hint: {'center_x': 0.15, 'center_y': 0.1}
font_size: 20
font_name: root.font_loc
on_press: pass
TextInput:
text:'Название компании'
multiline: False
size_hint: 0.40, 0.07
pos_hint: (None, 0.15)
font_size: 17
font_name: root.font_loc
Button:
text: 'Репутация'
size_hint: 0.30, 0.07
pos_hint: {'center_x': 0.45, 'center_y': 0.75}
font_size: 20
font_name: root.font_loc
Button:
text: 'Кредит'
size_hint: 0.30, 0.07
pos_hint: {'center_x': 0.60, 'center_y': 0.75}
font_size: 20
font_name: root.font_loc
Button:
text: 'Открытие рынков'
size_hint: 0.40, 0.07
pos_hint: {'center_x': 0.60, 'center_y': 0.75}
font_size: 20
font_name: root.font_loc
Button:
text: 'Доход'
size_hint: 0.30, 0.07
pos_hint: {'center_x': 0.60, 'center_y': 0.75}
font_size: 20
font_name: root.font_loc
как мне добавить класс Player_1 в layout в другом файле:
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from players import player_1
class Main(BoxLayout):
def __init__(self, **kwargs):
super(Main, self).__init__(**kwargs)
self.p1 = player_1.Player_1()
self.add_widget(self.p1)
class StartApp(App):
def build(self):
return Main()
if __name__ == "__main__":
StartApp().run()