Answer the question
In order to leave comments, you need to log in
How to add many buttons and other widgets in kivy?
Hey!
How can I make it so that there are 2 BoxLayouts and both of them are displayed?
My code:
# импорт
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.config import Config
import os
# настройки окна, размеры, запрет на масштабирование
Config.set('graphics', 'resizable', '0')
Config.set('graphics', 'width', '1300')
Config.set('graphics', 'height', '720')
# главный класс
class KivyEditorApp(App):
# функция создает .py файл проекта движка, где шаблон приложения kivy
def NewPrj(self, instance):
projectNew = open("newProject.py", "w+")
projectNew.write("from kivy.app import App\n")
projectNew.write("from kivy.config import Config\n")
projectNew.write("\n")
projectNew.write("Config.set('graphics', 'resizable', '0')\n")
projectNew.write("Config.set('graphics', 'width', '500')\n")
projectNew.write("Config.set('graphics', 'height', '500')\n")
projectNew.write("class NewProjectApp(App):\n")
projectNew.write(" def build(self):\n")
projectNew.write(" self.title = 'NewProject'\n")
projectNew.write(" pass\n")
projectNew.write('if __name__ == "__main__":\n')
projectNew.write(' NewProjectApp().run()\n')
self.title = "newProject.py"
# открывает проект
def OpenPrj(self, instance):
pass
# информация
def Info(self, instance):
print("KivyEditorApp (C) Stas Povalaev\npowered in Python 3.7.5")
# открытие документации в блокноте
def Help(self, instance):
os.system('documentation.txt')
# создать объект (текст)
def AddLabel(self, instance):
pass
# обязательная для kivy функция
def build(self):
self.formula = '0'
# BoxLayout на котором кнопки, которые открывают, создают проект и другие, его харастеристики
# настроены так, что бы кнопки были сверху как меню
bToolBar = BoxLayout(orientation = 'horizontal', size_hint=(None, None), size=(1300, 30), pos=(0, 690))
#gl = GridLayout(cols = 35, rows = 15, padding = [1], spacing = 3, row_force_default = True, row_default_height = 25)#52.65
# изменять корды виджетов можно создавая новые бокслаялуты, и изменяя же их размеры
# добавляем кнопки
bToolBar.add_widget(Button(text = 'New', on_press = self.NewPrj, background_color = [.2, .2, .2, 1], background_normal = '', font_size = 15))
bToolBar.add_widget(Button(text = 'Open', on_press = self.OpenPrj, background_color = [.2, .2, .2, 1], background_normal = '', font_size = 15))
bToolBar.add_widget(Button(text = 'Info', on_press = self.Info, background_color = [.2, .2, .2, 1], background_normal = '', font_size = 15))
bToolBar.add_widget(Button(text = 'Help', on_press = self.Help, background_color = [.2, .2, .2, 1], background_normal = '', font_size = 15))
bToolBar.add_widget(Button(text = '', background_color = [.2, .2, .2, 1], background_normal = '', font_size = 20))
bToolBar.add_widget(Button(text = '', background_color = [.2, .2, .2, 1], background_normal = '', font_size = 20))
bToolBar.add_widget(Button(text = '', background_color = [.2, .2, .2, 1], background_normal = '', font_size = 20))
bToolBar.add_widget(Button(text = '', background_color = [.2, .2, .2, 1], background_normal = '', font_size = 20))
bToolBar.add_widget(Button(text = '', background_color = [.2, .2, .2, 1], background_normal = '', font_size = 20))
bToolBar.add_widget(Button(text = '', background_color = [.2, .2, .2, 1], background_normal = '', font_size = 20))
bToolBar.add_widget(Button(text = '', background_color = [.2, .2, .2, 1], background_normal = '', font_size = 20))
self.lbl = Label(text = 'KivyEditorApp\nTest\nText for test', font_size = 15, halign = 'left', size_hint = (1, .4), text_size = (300 - 10, 400 * .4 - 10), valign = 'center', pos = (0, 0))
bToolBar.add_widget(self.lbl)
#bl.add_widget(gl)
return bToolBar
if __name__ == "__main__":
KivyEditorAppApp().run()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question