I was wondering if it is possible to use a variable as an argument in this case.
This is the code that I have:
def text_get_position(x, y, position):
if position == "midleft":
text_position = text_to_screen.get_rect(midleft=(x, y))
elif position == "midright":
text_position = text_to_screen.get_rect(midright=(x, y))
else:
text_position = text_to_screen.get_rect(center=(x, y))
I want to do something like:
def text_get_position(x, y, position):
text_position = text_to_screen.get_rect(position=(x, y))
I am sorry if it is already asked but I tried to look around and couldn't find a solution. Thanks in advance.
Yes, you can pass the named ("keyword") arguments as a dictionary. Note the ** in front of the dictionary.
def text_get_position(x, y, position):
text_position = text_to_screen.get_rect(**{position: (x, y)})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With