0
votes

I'm having issues with my constructor. I get the error __init__() missing 1 required positional argument: 'checkbutton'

Update:

this is my main file:

from GUI_Rootmodule import GUI_Root

gui_root = GUI_Root()

this is my rootmodule file:

from GUI_Unitmodule import Unit
from tkinter import *


class GUI_Root:
def __init__(self):
    print("hoi")
    window = Tk()
    window.title("Project: Embedded Systems")

    rootframe = Frame(window, width=1800, height=750)
    rootframe.pack()

    Unit(rootframe)

    window.mainloop()

this is my Unitmodule:

from tkinter import *


class Unit:
def __init__(self, master, checkbutton):
    self.frame1 = Frame(master)     #Frame voor labels, buttons, entries
    self.frame1.pack()

    # Checkbutton #
    print("test frame")
    self.var1 = IntVar()
    self.checkbutton = checkbutton(self.frame1, text="Automatisch", variable=self.var1, onvalue= 1, offvalue= 0, pady=20).grid(row=0, column=0, sticky=E)
    print("test checkbutton")

    # Labels #

    self.Extend_Label = Label(self.frame1, text="Uitrol afstand", pady=20).grid(row=2, column=0, sticky=E)
    self.Retract_Label = Label(self.frame1, text="Inrol afstand", pady=20).grid(row=3, column=0, sticky=E)
    self.Temperture_Label = Label(self.frame1, text="Temperatuur Trigger", pady=20).grid(row=4, column=0, sticky=E)
    self.LightIntensity_Label = Label(self.frame1, text="Lichtintensiteit Trigger", pady=20).grid(row=5, column=0, sticky=E)
    print("test label")

    # Entry #

    self.Extend_Entry = Entry(self.frame1).grid(row=2, column=1, sticky=E)
    self.Retract_Entry = Entry(self.frame1).grid(row=3, column=1, sticky=E)
    self.Temperture_Entry = Entry(self.frame1).grid(row=4, column=1, sticky=E)
    self.LightIntensity_Entry = Entry(self.frame1).grid(row=5, column=1, sticky=E)
    print("test entry")
    # Buttons

    self.A = Button(self.frame1, text ="Inrollen", padx=10, pady=20).grid(row=6, column=0)
    self.B = Button(self.frame1, text ="Uitrollen", padx=10, pady=20).grid(row=6, column=1)
    print("test button")

I've tried to run in it, but it keeps saying that I'm missing an argument which i've put in init(self, master, checkbutton)

Can someone explain what I'm missing here and/or doing wrong ?

Update 2: Without the checkbutton code, the rest works and shows a simple GUI. It's still not clear where exactly i'm missing the argument for checkbutton

1
Well, the error is telling you that your Unit class is expecting that argument, but you are not actually supplying it when you instantiate the class (which you have not shown). - Daniel Roseman
Please first fix your indentation, then post the full traceback and all the relevant code (edit your post, dont just add it as comments). - bruno desthuilliers
This. We don't even know which instantiation is causing the problem. - Max Uppenkamp
I've just added the rest of the code - lloydd4

1 Answers

1
votes

You didn't supply all of the required input parameters on this line:

 Unit(rootframe)

You supplied master, but are missing checkbutton. The class should be instantiated with all of the required input parameters:

Unit(master, checkbutton)

Alternatively, you can provide default values for the inputs and adjust the code in the function accordingly:

class Unit(master=None,checkbutton=None):
    ...

However, it looks like maybe you don't intend to pass in a checkbutton variable at all and meant to simply include a tkinter Checkbutton. If that's what you're after, I've included code for that below. I avoided the star import from tkinter import * so the source of the objects is more clear. I also combined things into the same module so the whole thing runs as-is.

import tkinter as tk

def main():
    gui_root = GUI_Root()

class GUI_Root:
    def __init__(self):
        print("hoi")
        window = tk.Tk()
        window.title("Project: Embedded Systems")

        rootframe = tk.Frame(window, width=1800, height=750)
        rootframe.pack()

        Unit(rootframe)

        window.mainloop()

class Unit:
    def __init__(self, master):
        self.frame1 = tk.Frame(master)     #Frame voor labels, buttons, entries
        self.frame1.pack()

        # Checkbutton #
        print("test frame")
        self.var1 = tk.IntVar()
        self.checkbutton = tk.Checkbutton(self.frame1, text="Automatisch", variable=self.var1, onvalue= 1, offvalue= 0, pady=20).grid(row=0, column=0, sticky=tk.E)
        print("test checkbutton")

        # Labels #

        self.Extend_Label = tk.Label(self.frame1, text="Uitrol afstand", pady=20).grid(row=2, column=0, sticky=tk.E)
        self.Retract_Label = tk.Label(self.frame1, text="Inrol afstand", pady=20).grid(row=3, column=0, sticky=tk.E)
        self.Temperture_Label = tk.Label(self.frame1, text="Temperatuur Trigger", pady=20).grid(row=4, column=0, sticky=tk.E)
        self.LightIntensity_Label = tk.Label(self.frame1, text="Lichtintensiteit Trigger", pady=20).grid(row=5, column=0, sticky=tk.E)
        print("test label")

        # Entry #

        self.Extend_Entry = tk.Entry(self.frame1).grid(row=2, column=1, sticky=tk.E)
        self.Retract_Entry = tk.Entry(self.frame1).grid(row=3, column=1, sticky=tk.E)
        self.Temperture_Entry = tk.Entry(self.frame1).grid(row=4, column=1, sticky=tk.E)
        self.LightIntensity_Entry = tk.Entry(self.frame1).grid(row=5, column=1, sticky=tk.E)
        print("test entry")
        # Buttons

        self.A = tk.Button(self.frame1, text ="Inrollen", padx=10, pady=20).grid(row=6, column=0)
        self.B = tk.Button(self.frame1, text ="Uitrollen", padx=10, pady=20).grid(row=6, column=1)
        print("test button")    

if __name__ == '__main__':
    main()