Я создал приложение Kivy, которое использует Python для управления созданием сложного динамического макета.
Я пытаюсь создать заданную строку меню слева, которая управляет содержимым, отображаемым в режиме прокрутки справа. p>
Я сделал это, создав отдельные классы Screen для каждой страницы, которые вызываются в классе ScreenManager. Затем я добавил макеты, сгенерированные Python, к соответствующим классам Screen в файле kivy. Сообщите мне, есть ли лучший способ справиться с этой проблемой.
Мое приложение должно иметь экран-заставку с меткой «Это экран-заставка». Как только вы нажмете «Создать слой», экран должен переключиться на страницу создания слоя, которая динамически управляет таблицей записей. Вместо этого у меня меню отображается правильно, но на месте прокрутки должен быть только пустой холст.
Файл Python:
#This file contains the graphical user interface logic of the DIS creator
from kivy.app import App
from kivy.metrics import dp
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.stacklayout import StackLayout
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.togglebutton import ToggleButton
from kivy.uix.screenmanager import ScreenManager, Screen
class DISCreatormanage(App):
pass
class Menu(StackLayout):
#Menu funcitons
def start_create_ply(self):
screen_manager.current = "create_ply_screen"
class Splash(GridLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
#Dimensional control
self.spacing = dp(5)
self.padding = dp(10)
self.cols = 1
self.size_hint = (1, None)
label = Label(text="This is the splash screen")
self.add_widget(label)
class CreatePly(GridLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
#Dimensional control
self.spacing = dp(5)
self.padding = dp(10)
self.cols = 1
self.size_hint = (1, None)
#Varibales
self.constituent_name = []
self.constituent_arealweight = []
self.structural = []
#Add and remove consituents
#Header
self.add_remove_header = BoxLayout()
self.add_remove_header.size_hint = (1, None)
self.add_remove_header.height = dp(40)
label = Label(text="Add constituents to create a ply")
self.add_remove_header.add_widget(label)
self.add_widget(self.add_remove_header)
#Add remove buttons
self.add_remove_buttons = GridLayout()
self.add_remove_buttons.cols = 4
self.add_remove_buttons.size_hint = (1, None)
self.add_remove_buttons.height = dp(40)
self.add_remove_buttons.add_widget(Widget())
button = Button(text="+", size_hint=(None, None), width=dp(40), height=dp(40))
button.bind(on_press = lambda x: self.add_constituent_press())
self.add_remove_buttons.add_widget(button)
button = Button(text="-", size_hint=(None, None), width=dp(40), height=dp(40))
button.bind(on_press = lambda x: self.remove_constituent_press())
self.add_remove_buttons.add_widget(button)
self.add_remove_buttons.add_widget(Widget())
self.add_widget(self.add_remove_buttons)
#Constituent table
self.constituent_table = GridLayout()
self.constituent_table.cols = 3
self.constituent_table.size_hint_y = None
self.constituent_table.bind(minimum_height=self.constituent_table.setter('height'))
label = Label(text="Consituent name", size_hint=(0.55, None), height=dp(20))
self.constituent_table.add_widget(label)
label = Label(text="Areal weight (g/m2)", size_hint=(0.3, None), height=dp(20))
self.constituent_table.add_widget(label)
label = Label(text="Structural?", size_hint=(0.15, None), height=dp(20))
self.constituent_table.add_widget(label)
textinput = TextInput(size_hint=(0.55, None), height=dp(40))
self.constituent_name.append(textinput)
self.constituent_table.add_widget(textinput)
textinput = TextInput(size_hint=(0.3, None), height=dp(40))
self.constituent_arealweight.append(textinput)
self.constituent_table.add_widget(textinput)
toggle = ToggleButton(text="No", size_hint=(0.15, None), height=(dp(40)))
toggle.bind(state=(lambda self, x: CreatePly.structural_constituent_toggle(self, toggle)))
self.structural.append(toggle)
self.constituent_table.add_widget(toggle)
self.add_widget(self.constituent_table)
#Build ply button
self.footer = GridLayout()
self.footer.cols = 3
self.footer.size_hint = (1, None)
self.footer.height = dp(40)
self.footer.add_widget(Widget())
button = Button(text="Create ply", size_hint=(None, None), width=dp(120), height=dp(40))
button.bind(on_press = lambda x: self.create_ply_click())
self.footer.add_widget(button)
self.footer.add_widget(Widget())
self.add_widget(self.footer)
#Create ply functions
def structural_constituent_toggle(self, toggle):
if toggle.state == "normal":
toggle.text = "No"
else:
toggle.text = "Yes"
def add_constituent_press(self):
textinput = TextInput(size_hint=(0.55, None), height=(dp(40)))
self.constituent_name.append(textinput)
self.constituent_table.add_widget(textinput)
textinput = TextInput(size_hint=(0.3, None), height=(dp(40)))
self.constituent_arealweight.append(textinput)
self.constituent_table.add_widget(textinput)
toggle = ToggleButton(text="No", size_hint=(0.15, None), height=(dp(40)))
toggle.bind(state=(lambda self, x: CreatePly.structural_constituent_toggle(self, toggle)))
self.structural.append(toggle)
self.constituent_table.add_widget(toggle)
def remove_constituent_press(self):
if len(self.constituent_name) == 1:
pass
else:
self.constituent_table.remove_widget(self.constituent_name[-1])
del self.constituent_name[-1]
self.constituent_table.remove_widget(self.constituent_arealweight[-1])
del self.constituent_arealweight[-1]
self.constituent_table.remove_widget(self.structural[-1])
del self.structural[-1]
def create_ply_click(self):
print("create ply click")
#Screen manager code
class SplashScreen(Screen):
pass
class CreaptePlyScreen(Screen):
pass
screen_manager = ScreenManager()
screen_manager.add_widget(SplashScreem(name="splash_screen"))
screen_manager.add_widget(CreaptePlyScreen(name="create_ply_screen"))
#Run loop
DISCreatormanage().run()
Файл KV:
#This file contains the graphical user interface elements of the DIS creator app
#This is the layout of the entire screen
MainLayout:
:
#Background colour
canvas.before:
Color:
rgba:(.3,.3,.3,1)
Rectangle:
pos: self.pos
size: self.size
padding: '10dp'
spacing: '10dp'
Menu:
FocusFrame:
#This is the layout for the menu which remains in place at all times.
:
#Background colour
canvas.before:
Color:
rgba:(0,0,0,1)
Rectangle:
pos: self.pos
size: self.size
#Dimension control
size_hint: None, 1
width: "160dp"
spacing: "2dp"
padding: "10dp"
Button:
text: "Create ply"
size_hint: 1, None
height: "40dp"
on_press:
root.start_create_ply()
#This places layouts in their respective screen classes
:
Splash:
:
CreatePly:
height: self.minimum_height
#This is the layout for the scrollable focus frame which will be changed on press of a menu button
:
canvas.before:
Color:
rgba:(0,0,0,1)
Rectangle:
pos: self.pos
size: self.size
ScreenManager:
Подробнее здесь: https://stackoverflow.com/questions/793 ... ank-screen
Kivy Screen Manager во вложенном коде Python отображает пустой экран ⇐ Python
Программы на Python
1736695997
Anonymous
Я создал приложение Kivy, которое использует Python для управления созданием сложного динамического макета.
Я пытаюсь создать заданную строку меню слева, которая управляет содержимым, отображаемым в режиме прокрутки справа. p>
Я сделал это, создав отдельные классы Screen для каждой страницы, которые вызываются в классе ScreenManager. Затем я добавил макеты, сгенерированные Python, к соответствующим классам Screen в файле kivy. Сообщите мне, есть ли лучший способ справиться с этой проблемой.
Мое приложение должно иметь экран-заставку с меткой «Это экран-заставка». Как только вы нажмете «Создать слой», экран должен переключиться на страницу создания слоя, которая динамически управляет таблицей записей. Вместо этого у меня меню отображается правильно, но на месте прокрутки должен быть только пустой холст.
Файл Python:
#This file contains the graphical user interface logic of the DIS creator
from kivy.app import App
from kivy.metrics import dp
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.stacklayout import StackLayout
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.togglebutton import ToggleButton
from kivy.uix.screenmanager import ScreenManager, Screen
class DISCreatormanage(App):
pass
class Menu(StackLayout):
#Menu funcitons
def start_create_ply(self):
screen_manager.current = "create_ply_screen"
class Splash(GridLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
#Dimensional control
self.spacing = dp(5)
self.padding = dp(10)
self.cols = 1
self.size_hint = (1, None)
label = Label(text="This is the splash screen")
self.add_widget(label)
class CreatePly(GridLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
#Dimensional control
self.spacing = dp(5)
self.padding = dp(10)
self.cols = 1
self.size_hint = (1, None)
#Varibales
self.constituent_name = []
self.constituent_arealweight = []
self.structural = []
#Add and remove consituents
#Header
self.add_remove_header = BoxLayout()
self.add_remove_header.size_hint = (1, None)
self.add_remove_header.height = dp(40)
label = Label(text="Add constituents to create a ply")
self.add_remove_header.add_widget(label)
self.add_widget(self.add_remove_header)
#Add remove buttons
self.add_remove_buttons = GridLayout()
self.add_remove_buttons.cols = 4
self.add_remove_buttons.size_hint = (1, None)
self.add_remove_buttons.height = dp(40)
self.add_remove_buttons.add_widget(Widget())
button = Button(text="+", size_hint=(None, None), width=dp(40), height=dp(40))
button.bind(on_press = lambda x: self.add_constituent_press())
self.add_remove_buttons.add_widget(button)
button = Button(text="-", size_hint=(None, None), width=dp(40), height=dp(40))
button.bind(on_press = lambda x: self.remove_constituent_press())
self.add_remove_buttons.add_widget(button)
self.add_remove_buttons.add_widget(Widget())
self.add_widget(self.add_remove_buttons)
#Constituent table
self.constituent_table = GridLayout()
self.constituent_table.cols = 3
self.constituent_table.size_hint_y = None
self.constituent_table.bind(minimum_height=self.constituent_table.setter('height'))
label = Label(text="Consituent name", size_hint=(0.55, None), height=dp(20))
self.constituent_table.add_widget(label)
label = Label(text="Areal weight (g/m2)", size_hint=(0.3, None), height=dp(20))
self.constituent_table.add_widget(label)
label = Label(text="Structural?", size_hint=(0.15, None), height=dp(20))
self.constituent_table.add_widget(label)
textinput = TextInput(size_hint=(0.55, None), height=dp(40))
self.constituent_name.append(textinput)
self.constituent_table.add_widget(textinput)
textinput = TextInput(size_hint=(0.3, None), height=dp(40))
self.constituent_arealweight.append(textinput)
self.constituent_table.add_widget(textinput)
toggle = ToggleButton(text="No", size_hint=(0.15, None), height=(dp(40)))
toggle.bind(state=(lambda self, x: CreatePly.structural_constituent_toggle(self, toggle)))
self.structural.append(toggle)
self.constituent_table.add_widget(toggle)
self.add_widget(self.constituent_table)
#Build ply button
self.footer = GridLayout()
self.footer.cols = 3
self.footer.size_hint = (1, None)
self.footer.height = dp(40)
self.footer.add_widget(Widget())
button = Button(text="Create ply", size_hint=(None, None), width=dp(120), height=dp(40))
button.bind(on_press = lambda x: self.create_ply_click())
self.footer.add_widget(button)
self.footer.add_widget(Widget())
self.add_widget(self.footer)
#Create ply functions
def structural_constituent_toggle(self, toggle):
if toggle.state == "normal":
toggle.text = "No"
else:
toggle.text = "Yes"
def add_constituent_press(self):
textinput = TextInput(size_hint=(0.55, None), height=(dp(40)))
self.constituent_name.append(textinput)
self.constituent_table.add_widget(textinput)
textinput = TextInput(size_hint=(0.3, None), height=(dp(40)))
self.constituent_arealweight.append(textinput)
self.constituent_table.add_widget(textinput)
toggle = ToggleButton(text="No", size_hint=(0.15, None), height=(dp(40)))
toggle.bind(state=(lambda self, x: CreatePly.structural_constituent_toggle(self, toggle)))
self.structural.append(toggle)
self.constituent_table.add_widget(toggle)
def remove_constituent_press(self):
if len(self.constituent_name) == 1:
pass
else:
self.constituent_table.remove_widget(self.constituent_name[-1])
del self.constituent_name[-1]
self.constituent_table.remove_widget(self.constituent_arealweight[-1])
del self.constituent_arealweight[-1]
self.constituent_table.remove_widget(self.structural[-1])
del self.structural[-1]
def create_ply_click(self):
print("create ply click")
#Screen manager code
class SplashScreen(Screen):
pass
class CreaptePlyScreen(Screen):
pass
screen_manager = ScreenManager()
screen_manager.add_widget(SplashScreem(name="splash_screen"))
screen_manager.add_widget(CreaptePlyScreen(name="create_ply_screen"))
#Run loop
DISCreatormanage().run()
Файл KV:
#This file contains the graphical user interface elements of the DIS creator app
#This is the layout of the entire screen
MainLayout:
:
#Background colour
canvas.before:
Color:
rgba:(.3,.3,.3,1)
Rectangle:
pos: self.pos
size: self.size
padding: '10dp'
spacing: '10dp'
Menu:
FocusFrame:
#This is the layout for the menu which remains in place at all times.
:
#Background colour
canvas.before:
Color:
rgba:(0,0,0,1)
Rectangle:
pos: self.pos
size: self.size
#Dimension control
size_hint: None, 1
width: "160dp"
spacing: "2dp"
padding: "10dp"
Button:
text: "Create ply"
size_hint: 1, None
height: "40dp"
on_press:
root.start_create_ply()
#This places layouts in their respective screen classes
:
Splash:
:
CreatePly:
height: self.minimum_height
#This is the layout for the scrollable focus frame which will be changed on press of a menu button
:
canvas.before:
Color:
rgba:(0,0,0,1)
Rectangle:
pos: self.pos
size: self.size
ScreenManager:
Подробнее здесь: [url]https://stackoverflow.com/questions/79350178/kivy-screen-manager-in-nested-python-code-is-displaying-a-blank-screen[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия