Enez Houad
Nov 20, 2020 - 10:37
I have been using Pythonista occasionally for two years now. With the help of the forum and by rummaging through the web, I manage to make some nice little applications. However, I regularly come up against basic problems related to my lack of Python skills. This is the case today ;-)
I can't understand why my script doesn't work.
I just want to make a class of Buttons... but my title doesn't display.
My mistake must be stupid, but I can't find it!
import ui
class MyButton (ui.View):
def __init__(self, *args, **kwargs):
self.btn = ui.Button()
for name in kwargs.keys():
value = kwargs[name]
self.__setattr__(name, value)
self.add_subview(self.btn)
def __setattr__(self, name, value):
print(f'• setattr : {name} = {value}')
if name != 'btn':
self.btn.__setattr__(name, value)
super().__setattr__(name, value)
if __name__ == '__main__':
mainView = ui.View( name='MyButton Demo',
bg_color='lightgrey',
frame=(0, 0, 400, 400))
myBtn = MyButton( name='MyButton',
title='Press me',
width=200)
myBtn.center = mainView.center
myBtn.y = 200
myBtn.background_color = 'red'
myBtn.tint_color = 'white'
mainView.add_subview(myBtn)
mainView.present('sheet')