I am making a time limit in Pycharm, but came across an error that says:
TypeError: ‘str’ object is not callable
How to fix this?
I am making a time limit in Pycharm, but came across an error that says:
TypeError: ‘str’ object is not callable
How to fix this?
Hi, @amel8star!
You error is from this:
"{}:{}:{}"(hours, mins, secs)
You cannot call a string.
It seems like you were trying to format the string.
You can do that using the str.format
function:
"{}:{}:{}".format(hours, mins, secs)
I tried put the solution u said, but it still did give me the error. Did i do something wrong here or forget?
There are two problems in that line: there is an extra quote at the start of the string, and you forgot to put a comma between the first and second arguments of font.render
.
text = font.render("{}:{}:{}".format(hours, mins, secs), True, (255, 255, 255), (0, 0, 0))
You should also consider using formatted string literals if your python version >= 3.6.
text = font.render(f"{hours}:{mins}:{secs}", True, (255, 255, 255), (0, 0, 0))
Also, there seems to be more problems in other lines of your code. Did you mean:
textRect = text.get_rect()
on line 16?
In your loop on line 20, you are incrementing secs
by one for every millisecond that passes because clock.tick
takes milliseconds as its argument, not seconds. Did you mean: clock.tick(1000)
or secs += 0.001
?
So the second one, like the middle u typed is the correct one?
And by ur last question about the time i meant secs += 0.001
The first code snippet is equivalent to the second one. The second one is probably better, but make sure you understand how it works.
It did work, thank you for the help.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.