TypeError Missing Positional Arguments? What is going on? --Python and Tkinter

Related searches

Im trying to code a simple tkinter program that returns reddit information back to the user. In doing so, I'm receiving the error message:

Traceback (most recent call last):
  File "redditscraper4.py", line 111, in <module>
    app = RedditScraper()
  File "redditscraper4.py", line 23, in __init__
    frame = F(container, self)
  File "redditscraper4.py", line 93, in __init__
    get_user_entry_string = get_user_entry.addBrackets()
  File "redditscraper4.py", line 62, in addBrackets
    user_entry = StartPage()
TypeError: __init__() missing 2 required positional arguments: 'parent' and 'controller'

I have absolutely no clue as to what I've done wrong with my code. Im lost, and nowhere on the Web seems to have a coherent answer to this problem.

Here is my code:

import tkinter as tk
from functools import partial
from webbrowser import open
from datetime import date
import praw


'''Initialising the Applicaiton'''
class RedditScraper(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        container = tk.Frame(self)

        container.pack(side="top", fill="both", expand = True)

        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        for F in (StartPage, redditReturn):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(StartPage)

    def show_frame(self, cont):
        frame = self.frames[cont]
        frame.tkraise()

'''The First Page the User will see'''
class StartPage(tk.Frame, object):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label1 = tk.Label(self, text="Start Page")
        label1.pack(pady=10, padx=10)

        button1 = tk.Button(self, text="Scrape This Subreddit", command=lambda: controller.show_frame(redditReturn))
        button1.pack(pady=10, padx=10)

        self.entry_var = tk.StringVar()
        e1 = tk.Entry(self,textvariable=self.entry_var)
        e1.pack(pady=10, padx=10)

        StartPage.entry1 = self.entry_var.get()



'''Adding brackets around the user's entry to the label to suffice the praw api'''      
class bracketEntry(object):

    def addBrackets(self):

        user_entry = StartPage()
        get_user_entry_string = user_entry.entry1()

        user_entry_plus_brackets = '"' + get_user_entry_string + '"'

        print(user_entry_plus_brackets)
        return user_entry_plus_brackets


'''Collecting data from reddit'''
class redditCollect(object):

    def getSubreddit(self):
        user_agent = "Simple Subreddit Scraper"
        r = praw.Reddit(user_agent=user_agent)
        '''remember to add the ability to get the user-defined subreddit information'''
        user_entry = bracketEntry()
        user_entry_variable = user_entry.addBrackets()
        posts = r.get_subreddit("pics").get_hot(limit = 10)
        return posts



'''The window containing the information from Reddit for the user'''        
class redditReturn(tk.Frame, object):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        """Creates all the buttons and frames for the GUI"""
        get_user_entry = bracketEntry()
        get_user_entry_string = get_user_entry.addBrackets()

        intro = get_user_entry_string + " on Reddit: "
        newFrame = tk.LabelFrame(self, text = intro)
        newFrame.pack(fill="both", expand= True , anchor="nw")        
        row = 0
        redditCollectGetter = redditCollect()
        local_posts = redditCollectGetter.getSubreddit()
        for p in local_posts:
            gotoArticle = partial(open, p.url)
            title = "(" + str(p.score) +") " + p.title
            tk.Label(newFrame, text= title, pady= 10, wraplength= 700, justify= "left").grid(row= row, column= 0, sticky= "w")
            tk.Button(newFrame, text= "Read more!", command= gotoArticle).grid(row= row+1, column= 0, sticky= "w")
            tk.row = row + 2




app = RedditScraper()
app.mainloop()

Any help is appreciated! Thanks!

In your bracketEntry class, in the addBrackets method, you call user_entry = StartPage(). However, you declare StartPage's __init__ method as def __init__(self, parent, controller):, which means you have to provide parent and controller arguments.


Edit: To fix the method, you are going to have to pass the parent and controller objects all the way down the call stack or find another way of getting them into the addBrackets method. E.g., you could redefine def addBrackets(self, parent, controller), and then update the infringing line: user_entry = StartPage(parent, controller). You would then have to update all calls to addBracket to include the new argument.

Button command getting TypeError: radsa() missing , Error: TypeError: radsa() missing 3 required positional arguments: and 'g�t' import tkinter import math import random import time from tkinter import. There are a couple of ways to do this, the cleanest is with partial Python Coding, -- General Coding Help, -- Data Science, -- Homework, -- GUI, -- Game� If you don't, the function fails. You don't use the name parameter, so you should probably just remove it. You're going to have the same problem with your other getters. BTW, this is Python, not Java. You never almost never use getters and setters in Python. They slow things down, make your code harder to understand, and don't actually do anything.

You've defined the __init__ method of StartPage to take two required arguments, parent and controller. But in the line that's causing the error, you are just calling StartPage() without passing those arguments. As the error says, you need to pass them.

Missing 2 Required Positional Arguments, Hello, I am new to python and so I am following a tutorial to learn about from tkinter import messagebox our grid lines TypeError: drawGrid() missing 2 required positional arguments: Private Messages, User Control Panel, Who's Online, Search, Forum Home, Python Coding, -- General Coding Help� In this tutorial of Python Examples, we have learned to solve the TypeError: method() takes 0 positional arguments but 1 was given, with the help of example programs. Like what you read! Bookmark this page for quick access and please share this article with your friends and colleagues.

import tkinter as tk
from functools import partial
from webbrowser import open
from datetime import date
import praw

'''Initialising the Applicaiton'''


class RedditScraper(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        container = tk.Frame(self)

        container.pack(side="top", fill="both", expand=True)

        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        for F in (StartPage, redditReturn):
            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(StartPage)

    def show_frame(self, cont):
        frame = self.frames[cont]
        frame.tkraise()


'''The First Page the User will see'''


class StartPage(tk.Frame, object):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label1 = tk.Label(self, text="Start Page")
        label1.pack(pady=10, padx=10)

        button1 = tk.Button(self, text="Scrape This Subreddit", command=lambda: controller.show_frame(redditReturn))
        button1.pack(pady=10, padx=10)

        self.entry_var = tk.StringVar()
        e1 = tk.Entry(self, textvariable=self.entry_var)

        e1.pack(pady=10, padx=10)
        global save
        save = tk.StringVar()
        save = e1.get()

        # StartPage.entry1: str = self.entry_var.get()

    def entry1(self):
        global save
        user_input = tk.StringVar()
        user_input = save
        return save


'''Adding brackets around the user's entry to the label to suffice the praw api'''


class bracketEntry(object):

    def addBrackets(self, parent, controller):
        user_entry = StartPage(parent, controller)

        #  * Takes in inputs as parent and the controller

        get_user_entry_string = user_entry.entry1()

        user_entry_plus_brackets = '"' + get_user_entry_string + '"'

        print(user_entry_plus_brackets)
        return user_entry_plus_brackets


'''Collecting data from reddit'''


class redditCollect(object):

    def getSubreddit(self, parent, controller):
        user_agent = "Simple Subreddit Scraper"
        r = praw.Reddit(user_agent=user_agent)
        '''remember to add the ability to get the user-defined subreddit information'''
        user_entry = bracketEntry()
        user_entry_variable = user_entry.addBrackets(parent,controller)
        print(user_entry_variable)  # prints the quoted string in the Entry field
        posts = r.get_subreddit("pics").get_hot(limit=10)
        return posts


'''The window containing the information from Reddit for the user'''


class redditReturn(tk.Frame, object):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        """Creates all the buttons and frames for the GUI"""
        get_user_entry = bracketEntry()

        # * takes in no inputs

        get_user_entry_string = get_user_entry.addBrackets(parent, controller)

        intro = get_user_entry_string + " on Reddit: "
        newFrame = tk.LabelFrame(self, text=intro)
        newFrame.pack(fill="both", expand=True, anchor="nw")
        row = 0
        redditCollectGetter = redditCollect()
        local_posts = redditCollectGetter.getSubreddit(parent,controller)
        for p in local_posts:
            gotoArticle = partial(open, p.url)
            title = "(" + str(p.score) + ") " + p.title
            tk.Label(newFrame, text=title, pady=10, wraplength=700, justify="left").grid(row=row, column=0, sticky="w")
            tk.Button(newFrame, text="Read more!", command=gotoArticle).grid(row=row + 1, column=0, sticky="w")
            tk.row = row + 2


app = RedditScraper()

"TypeError: missing 1 required positional argument: 'self'" that I don't , "TypeError: missing 1 required positional argument: 'self'" that I don't know how to fix a function to a Tkinter button and that function doesn't accept any arguments , you __class__.bar(a) -- the key being that an instance of the Foo class got passed I'm learning Python without any education in Computer Science — what� TypeError: get() takes 1 positional argument but 3 were given Tag: python , tkinter This code will run a basic data input window through tkinter which will save the user's inputs.

Missing required positional arguments, TypeError: __init__() missing 1 required positional argument: 'activities' Below it isn't going in the parent class init? missing 1 required positional argument: 1 required positional argument: 'number' 8427 views 1 hour ago python tkinter . 1 required positional argument: 'kvlist' fish: Job 1, 'bean-check --verbose ledger. Short answer: A positional argument is any argument that's not supplied as a key=value pair. To understand what that means, unfortunately, is somewhat involved.

Missing 1 required positional argument: 'x', Missing 1 required positional argument: 'x' - python. from tkinter import * import math def calculate(x): while x**2+math.sqrt(x) < 4: x TypeError: callback() takes exactly 2 arguments (1 given) The 1 argument is "self" Can you see what I am doing wrong? --output:-- Storm Next: def do_stuff(x, y): print(x, y) tk. Hi Guys, I am studying a mark scheme answer from a previous exam question and when following the mark scheme on Python , I am presented with an error: TypeError: __init__() missing 3 required positional arguments: 'MemberName', 'MemberID', and 'Subs

I was trying to run evaluate.py with cityscapes dataset in the path as below in Windows 10 (Git Bash) using Python 3.5.2 and tensorflow-gpu 1.3.0 I have modified data directory path with my local path as below path DATA_DIRECTORY = './da

Comments
  • I changed the line in my bracketEntry class to def addBrackets(parent, controller): but I'm still getting an error to add another 'controller' positional argument. Thanks for your help!
  • @JeffD I've added some more detail on how you'd go about fixing the problem. The key questions to ask yourself are "Where do I define the parent widget and the controller?" and "How do I pass these objects to the actual call?"
  • Please add some explanation to your code such that others can learn from it