I'm designing a security camera program. Right now, I am just trying to set up the GUI before receiving. I am using Kivy since, in the future, I plan on designing some programs for Android. I really like Python, and I figured I'd start learning Kivy.

My question is: am I building the GUI structure correctly?

The layout I have planned is for the core container to have a BoxLayout that will hold three containers:

  • The first container is on the left and will hold buttons to perform various commands.
  • The second container will be in the center and will hold all the video feeds.
  • The third container will be on the right and its purpose is still being considered.

import kivy
from kivy.config import Config
Config.set('graphics', 'fullscreen', 'auto')
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.anchorlayout import AnchorLayout

class camMonitor(BoxLayout):

    def __init__(self, **kwargs):
        super(camMonitor, self).__init__(**kwargs)

class controlInterface(BoxLayout):

    def __init__(self, **kwargs):
        super(controlInterface, self).__init__(**kwargs)
        button1 = Button(text='action 1', size =(50,30), size_hint=(None,None))

class camMonApp(App):

    def build(self):
        return camMonitor()

if __name__ == '__main__':

For each container, I have created a separate class. Not every class will be a box layout; that's just what I have it set to at the moment.

Should I continue building the GUI the way it is now, or should everything be put into one class?


tl;dr: If you are planning on adding more methods to each of these classes, then use them. If not, then don't.

One of the first things you should check when deciding whether to use a class or not, is if the class has two or less methods, __init__, and another function. Since your code doesn't like complete quite yet, I'm making the assumption that there will be more functions added to each of these classes.

Now, I do have a few things about your code that I want to point out. Here's a list of small things you could improve.

  1. Class names should be in PascalCase. Not lowerCasePascalCase.
  2. There should be two blank lines between each class/function/code block on the top level of your file.
  3. You have a blank line before each of your class declarations. Preferably, you should either, put a docstring here, or, remove the blank line.

If you want to make sure that your code is PEP8 compliant, you can visit PEP8's page here, or use this online PEP8 checker here. If you want a checker on your local machine, you can just run pip install pep8, and to update, you can run pip install --upgrade pep8.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.