Home > other >  Tkinter | TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given
Tkinter | TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

Time:05-09

Code is meant to take the input from the tkinter entry widget, cam1, and assign to cam1_name, to then be appended to a list with its associated callback function. Obviously, it does not and throws the error above. Any help would be appreciated. Thanks!


import tkinter as tk
from tkinter import ttk

root = tk.Tk()    # my main window

def cam1_name_func():
    cam1_name.get()
    amendations["camOne"] = cam1_name

cam1_name = tk.StringVar()
cam1 = ttk.Checkbutton(root, cam1_name).pack()  # error happens on this line

root.mainloop()

CodePudding user response:

To fix the error, you need to use the text keyword for the second argument of Checkbutton. All the options for Checkbutton need to be listed as key=value after the parent window argument.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()    # my main window

def cam1_name_func():
    cam1_name.get()
    amendations["camOne"] = cam1_name

cam1_name = tk.StringVar()
cam1 = ttk.Checkbutton(root, text=cam1_name).pack()

root.mainloop()
  • Related