peterhinch / micropython-micro-gui

A lightweight MicroPython GUI library for display drivers based on framebuf, allows input via pushbuttons. See also micropython-touch.
MIT License
247 stars 37 forks source link

Having error File "gui/core/ugui.py", line 420, in __init__ AttributeError: 'NoneType' object has no attribute 'height' #24

Closed AkshatChauhan18 closed 1 year ago

AkshatChauhan18 commented 1 year ago
import hardware_setup  
from gui.core.ugui import Screen,ssd

from gui.widgets import CloseButton, Checkbox, LED
from gui.core.writer import Writer

import gui.fonts.arial10 as arial10
from gui.core.colors import *

class BaseScreen(Screen):

    def __init__(self):

        super().__init__()
        wri = Writer(ssd, arial10, verbose=False)
        col = 2
        row = 2
        self.cb = Checkbox(wri, row, col, callback=self.cbcb)
        col+= 40
        self.led = LED(wri, row, col, color=YELLOW, bdcolor=GREEN)
        CloseButton(wri)

    def cbcb(self, cb):
        self.led.value(cb.value())

def test():
    print('Checkbox demo.')
    Screen.change(BaseScreen)

test()

while running this code I am getting an error:

Traceback (most recent call last): File "", line 38, in File "", line 36, in test File "gui/core/ugui.py", line 328, in change File "", line 22, in init File "gui/core/ugui.py", line 420, in init AttributeError: 'NoneType' object has no attribute 'height'

peterhinch commented 1 year ago

Please show me your hardware_setup.py.

AkshatChauhan18 commented 1 year ago

I am using ssd1306 oled display therefore i used this code for hardware_setup.py

from machine import Pin, SoftI2C
import gc

from drivers.ssd1306.ssd1306 import SSD1306_I2C as SSD

i2c = SoftI2C(scl=Pin(22), sda=Pin(21))

oled_width = 128
oled_height = 64
gc.collect()  # Precaution before instantiating framebuf
ssd = SSD(oled_width, oled_height, i2c)
peterhinch commented 1 year ago

Your setup file appears to be designed for nanogui.

In microgui you need to define your control buttons and create a display object. Please study the docs and the microgui setup examples.

peterhinch commented 1 year ago

Closing due to inactivity.