Python Forum
[Tkinter] Takes 1 Positional Argument but 2 were Given
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Takes 1 Positional Argument but 2 were Given
#1
This is the code I have.

self.contrast = Scale(root, command=self.editingImage, from_= -100, to = 100, orient = HORIZONTAL)

I am trying to call the function editingImage(self) whenever the scale is moved, but python keeps giving me the error:

TypeError: editingImage() takes 1 positional argument but 2 were given

Why is this? I am only putting in one argument, self. At least I think I am?
Reply
#2
Try this and you'll see, that the command is called with one argument. The current Value.
import tkinter
root = tkinter.Tk()
tkinter.Scale(root, command=print, from_=0, to=200, orient=tkinter.HORIZONTAL).pack()
tkinter.Button(root, text='Close', command=root.destroy).pack()
root.mainloop()
Maybe you have forgotten to add the argument into your method. When there is only editingImage(self):, it's wrong.
The callback command is called with one argument.
Use instead editingImage(self, value): and do something with value in your editingImage method.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
That worked! Thank you so much.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Kivy] Type error:takes 1 positional argument but 2 required hammer 3 2,654 Nov-09-2021, 06:01 AM
Last Post: deanhystad
  Syntax Error: Positional argument follows keyword argument Rama02 3 4,104 Feb-09-2021, 06:10 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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