Python Forum
TypeError: setText(self, str): too many arguments
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: setText(self, str): too many arguments
#1
My code is meant to multiply a number with pi, but when I run it I get the error: TypeError: setText(self, str): too many arguments
def pi(self):
        if self.tall_input.text() == "" or self.tall_input.text() == 0:
            self.tall_input.setText(format(math.pi), '.15g')
        else: 
            self.tall_input.setText(format(float(self.tall_input.text()) * math.pi), '.15g')
I get the error on both the 'if' and the 'else', so I'm guessing the problem is with the format() function, but I don't what.
Reply
#2
You need to move , '.15g' inside the call to the format function. As it is now, it's a parameter to setText, when I think you want it as a parameter to format. That is, format(math.pi, '.15g') and the same on line 5.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Thank you for the help!
Reply
#4
setText() expects a string but you are passing it a tuple, a possible solution is:

self.label_2.setText(str(circles.shape))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 1,858 Oct-17-2022, 06:29 PM
Last Post: paulo79
  TypeError: not enough arguments for format string MaartenRo 6 2,860 Jan-09-2022, 06:46 PM
Last Post: ibreeden
  TypeError: missing 3 required positional arguments: wardancer84 9 10,663 Aug-19-2021, 04:27 PM
Last Post: deanhystad
  TypeError: max_value() missing 2 required positional arguments: 'alpha' and 'beta' Anldra12 2 4,167 May-15-2021, 04:15 PM
Last Post: Anldra12
  TypeError: add() missing 2 required positional arguments NectDz 5 12,959 May-28-2020, 02:54 PM
Last Post: BitPythoner
  TypeError: not all arguments converted during string formatting RedSkeleton007 1 14,906 Jul-15-2018, 08:51 PM
Last Post: ichabod801
  Functions (Arguments Passing,Changing a mutable ,Assignment to Arguments Names) Adelton 2 3,817 Mar-02-2017, 10:23 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020