What I’m trying to do:
I am just at this point trying to get the feel of Python and Anvil, so I copied a You Tube tutorial, which was great and we created a little calculator. However, I wanted to see how I could add custom CSS to it. As such, I have created a custom role called btnround and want to assign this instead of the regular button.
I added this custom CSS to it:
anvil-role-btnround{
border-radius:50px;
border: 2px;
padding:3px;
}
I want to put it in here
self.btnround = {}
If I put
self.anvil-role-btnround = {}
I get a syntax error
The SyntaxError: cannot assign to operator error is raised when you try to evaluate a mathematical statement before an assignment operator. To fix this error, make sure all your variable names appear on the left hand side of an assignment operator and all your mathematical statements appear on the right.
What I’ve tried and what’s not working:
I want to put it in this code, but as soon as I enter the first one I get the syntax error
Code Sample:
class Form1(Form1Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
chars = ["1", "2", "3", "4", "d", "c",
"5", "6", "7", "8", "+", "-",
"9", "0", ".", "*", "/", "="]
self.anvil-role-btnround = {}
gp = GridPanel()
for idx, i in enumerate(chars):
if i =="=":
clr = "#2e536e"
elif i in ["c", "d"]:
clr = "#ef2e36"
elif i in ["+", "-", "*", "/"]:
clr = "#3A3A49"
else:
clr = "#EE8A8A"
if idx < 6:
row = 'A'
elif 6<=idx<12:
row = 'B'
else:
row = 'C'
self.btnround[i] = Button(text=i,
font ="Consolas",
bold= True,
foreground="#FFF",
background=clr)
self.btnround[i].tag.name = i
self.btnround[i].set_event_handler('click', self.click)
gp.add_component(self.btnround[i], row=row, col_xs=3, width_xs=1)
self.add_component(gp)
def click(self, **event_args):
val = event_args['sender'].tag.name
if val == "=":
self.text_box_1.text = eval(self.text_box_1.text)
elif val =="c":
self.text_box_1.text = ""
elif val =="d":
self.text_box_1.text = self.text_box_1.text[:-1]
else:
self.text_box_1.text += val
https://hasty-wry-tiger.anvil.app
Can you help with the right way to put this custom role into this script, many thanks