Python TypeError: __init__() got multiple values for argument master

2024/9/19 9:26:41

Trying to build a GUI in Python at the moment, and I'm stuck at this part in particular. Every time I try to run my code it just throws the error TypeError: __init__() got multiple values for argument 'master'. I can't seem to find where I'm passing it more than one value, and it's got me scratching my head. I tried searching the error but the fixes other people had listed I can't see how to make them work with this one. Any guidance would be much appreciated. See code sample below:

class Plotter(tk.Canvas):"""Creates a canvas for use in a GUIPlotter() -> Canvas"""def __init__(self, master, **kwargs):super().__init__(self, master = master, **kwargs)self.bind("<Configure>", self.on_resize)self.height = self.winfo_reqheight()self.width = self.winfo_reqwidth()self.bg = 'white'self.relief = 'raised'class AnimalDataPlotApp(object):"""This is the top level class for the GUI, and is hence responsible forcreating and maintaining instances of the above glasses"""def __init__(self, master):"""Initialises the window and creates the base window for the GUI.__init__() -> None"""master.title('Animal Data Plot App')self._master = masterself._text = tk.Text(master)self._text.packmenubar = tk.Menu(master)master.config(menu = menubar)filemenu = tk.Menu(menubar) #puts filemenu into the menubarmenubar.add_cascade(label = 'File', menu = filemenu)filemenu.add_command(label = 'Open', command = self.open_file)#frame for canvasplotter_frame = tk.Frame(master, bg = 'red')plotter_frame.pack(side = tk.RIGHT, anchor = tk.NW, fill = tk.BOTH, expand = True)#frame for buttonsbutton_frame = tk.Frame(master, bg = 'yellow')button_frame.pack(side=tk.TOP, anchor=tk.NW, ipadx=50, fill = tk.X)#Label on the top leftleft_label = tk.Label(button_frame, text='Animal Data Sets', bg='orange')left_label.pack(side=tk.TOP, anchor=tk.N, fill=tk.X)#second frame, for selection listselection_frame = tk.Frame(master, bg = 'blue')selection_frame.pack(side = tk.LEFT, anchor=tk.NW, fill = tk.BOTH, expand = True)#draw buttons in frameselect = tk.Button(button_frame, text ='Select')select.pack(side=tk.TOP, anchor=tk.N)deselect = tk.Button(button_frame, text='Deselect')deselect.pack(side=tk.TOP, anchor=tk.N)self.selectionbox = SelectionBox(selection_frame)self.selectionbox.pack(side = tk.TOP, expand = True, fill=tk.BOTH)#self._selectionbox.show_animals(self._data)self.plotter = Plotter(plotter_frame)self.plotter.pack(side = tk.TOP, expand = True, fill=tk.BOTH)
Answer
super().__init__(self, master = master, **kwargs)

If you're using super(), you don't need to specify self explicitly.

You are getting that error because self is being interpreted as the argument for master. So it's like if you were calling __init__(master=self, master=master, **kwargs).

https://en.xdnf.cn/q/72659.html

Related Q&A

How to suppress all warnings in window of executable file generated by pyinstaller

I have generated an executable file from a python file using pyinstaller. The program works how it is supposed to work but there is this warning message it appears in the window that I would like to hi…

Python requests gives me bad handshake error

Using Python requests like thisimport requests; requests.get(https://internal.site.no)gives me an error many have had;SSLError: ("bad handshake: Error([(SSL routines, SSL23_GET_SERVER_HELLO, sslv3…

PyCharm: Storing variables in memory to be able to run code from a checkpoint

Ive been searching everywhere for an answer to this but to no avail. I want to be able to run my code and have the variables stored in memory so that I can perhaps set a "checkpoint" which I …

Execute bash script from Python on Windows

I am trying to write a python script that will execute a bash script I have on my Windows machine. Up until now I have been using the Cygwin terminal so executing the bash script RunModels.scr has been…

Python regex convert youtube url to youtube video

Im making a regex so I can find youtube links (can be multiple) in a piece of HTML text posted by an user.Currently Im using the following regex to change http://www.youtube.com/watch?v=-JyZLS2IhkQ in…

Python / Kivy: conditional design in .kv file

Would an approach similar to the example below be possible in Kivy? The code posted obviously doesnt work, and again its only an example: I will need different layouts to be drawn depending on a certa…

z-axis scaling and limits in a 3-D scatter plot

I performed a Monte Carlo inversion of three parameters, and now Im trying to plot them in a 3-D figure using Matplotlib. One of those parameters (Mo) has a variability of values between 10^15 and 10^2…

How to fix value produced by Random?

I got an issue which is, in my code,anyone can help will be great. this is the example code.from random import * from numpy import * r=array([uniform(-R,R),uniform(-R,R),uniform(-R,R)])def Ft(r):f…

Can I safely assign to `coef_` and other estimated parameters in scikit-learn?

scikit-learn suggests the use of pickle for model persistence. However, they note the limitations of pickle when it comes to different version of scikit-learn or python. (See also this stackoverflow qu…

How to update the filename of a Djangos FileField instance?

Here a simple django model:class SomeModel(models.Model):title = models.CharField(max_length=100)video = models.FileField(upload_to=video)I would like to save any instance so that the videos file name …