简体   繁体   中英

TypeError: PNI() missing 1 required positional argument: 'self'

Any help with this problem would be much appreciated. I keep getting the below error and can not figure out why.

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Beast\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
TypeError: PNI() missing 1 required positional argument: 'self'

Below is the code that I have so far. From what I can tell the problem is caused by the def PNI function. I have tried that function is a simplified program and it worked so any help making it work here will be much appreciated.

from tkinter import *
import pandas as pd
import os
import shutil
import time

#Font sizes
LARGE_FONT = ("Verdana", 12)

#Main frame
class IntegrationAPP(Tk):

    def __init__(self, *args, **kwargs):
    
        Tk.__init__(self, *args, **kwargs)
        container = 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, Test):
            
            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()

class StartPage(Frame):

    def __init__(self, parent, controller, *args, **kwargs):
        Frame.__init__(self, parent)

        #Create entry feild
        pni = Entry(self, width=50)
        pni.insert(0, 'Enter project number')

        #Pull data from entry feild
        def PNI(self, *args, **kwargs):
            label1 = Label(self, text = pni.get())
            label1.grid(row=0, column=2)

        #Create submit button
        buttonpni = Button(self, text="Submit", command=PNI)

        #Location in grid
        pni.grid(row=0, column=0)
        buttonpni.grid(row=1, column=0)

#Future epansion
class Test(Frame):

    def __init__(self, parent, controller):
        Frame.__init__(self,parent)
        label1 = Label(self, text="Hello", font=LARGE_FONT)
        
        label1.grid(row=0, column=0)

app = IntegrationAPP()
app.mainloop()

Thank you for any help you are able to provide.

Move this to the left, currently it's inside init function. Just an indentation problem basically. Usually most IDEs offer you to move selected code left and right with ctrl+{ or ctrl+}

 #Pull data from entry feild
    def PNI(self, *args, **kwargs):
        label1 = Label(self, text = pni.get())
        label1.grid(row=0, column=2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM