为什么我会收到TypeError:__ init __()缺少1个必需的位置参数:' master'?

时间:2015-04-28 15:09:54

标签: python python-3.x tkinter python-imaging-library

node_modules/
plugins/
platforms/ios/TruckBlox/Plugins
platforms/ios/TruckBlox/main.m
platforms/ios/TruckBlox/Classes
platforms/ios/TruckBlox/TruckBlox-Info.plist
platforms/ios/TruckBlox/TruckBlox-Prefix.pch
platforms/ios/TruckBlox/config.xml
platforms/ios/TruckBlox/Resources/icons
platforms/ios/build
platforms/ios/cordova
platforms/ios/CordovaLib
platforms/ios/platform_www
platforms/ios/TruckBlox.xcodeproj
platforms/ios/www

!platforms/ios/TruckBlox/Resources/splash/
!platforms/ios/TruckBlox/Resources/splash/*

目前,我收到了错误

#Imports#
import sys
sys.path.append("F:\A2\Computing\Comp 4\Python34\Lib\site-packages")

from tkinter import *
import tkinter as tk
from PIL import Image, ImageTk

#Main Code#


class GUIImage(tk.Tk):
    def __init__(self, master, *pargs):
        tk.Tk.__init__(self, master, *pargs)

        self.image = Image.open("F:\A2\Computing\Comp 4\Code\main.jpg")
        self.img_copy= self.image.copy()

        self.background_image = ImageTk.PhotoImage(self.image)

        self.background = Label(self, image=self.background_image)
        self.background.pack(fill=BOTH, expand=YES)
        self.background.bind('<Configure>', self._resize_image)

        self.frames={}

        for F in(mainMenuGUI,addUserGUI,delUserGUI,visitorGUI,prechkGUI,userManual):
            frame = F(container, self)
            self.frames[Frames] = frame
            frame.grid(row=0,column=0,sticky="nsew")

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

    def _resize_image(self,event):

        new_width = event.width
        new_height = event.height

        self.image = self.img_copy.resize((new_width, new_height))

        self.background_image = ImageTk.PhotoImage(self.image)
        self.background.configure(image =  self.background_image)


class mainMenuGUI(tk.Frame):
    def __init__(self,parent,controller):
        tk.Frame.__init(self,parent)
        mainMenuGUI = GUIImage(App)
        mainMenuGUI.pack(fill=BOTH, expand=YES)
        MMText = Label(self, text ="Main Menu",bg ="#FD7F17", font = ("Arial Black",18)).place(relx=.40, rely=.05)
        MMButton1= Button(self, text = "Add User", fg = "white",bg = "dark grey", command = lambda:controller.show_frame(addUserGUI),height = "1", width ="10", font = ("Arial Black",14)).place(relx =.38 , rely=.14)
        MMButton2= Button(self, text = "Delete User", fg = "white",bg = "dark grey", command = lambda:controller.show_frame(delUserGUI),height = "1", width ="10", font = ("Arial Black",14)).place(relx =.38 , rely=.28)
        MMButton3= Button(self, text = "Add Visitor", fg = "white",bg = "dark grey", command = lambda:controller.show_frame(VisitorGUI),height = "1", width ="10", font = ("Arial Black",14)).place(relx =.38 , rely=.42)
        MMButton4= Button(self, text = "Premises Check", fg = "white",bg = "dark grey", command =   lambda:controller.show_frame(prechkGUI) ,height = "1", width ="14", font = ("Arial Black",14)).place(relx =.32 , rely=.56)
        MMButton5= Button(self, text = "Vehicle Check", fg = "white",bg = "dark grey", command = "navVehChe",height = "1", width ="14", font = ("Arial Black",14)).place(relx =.32 , rely=.70)
        MMButton6= Button(self, text = "User Manual", fg = "white",bg = "dark grey", command =  lambda:controller.show_frame(userManual),height = "1", width ="10", font = ("Arial Black",14)).place(relx =.38 , rely=.84)

App = GUIImage()
App.mainloop()

当它运行时,我对它为什么不起作用有一个模糊的概念。

1 个答案:

答案 0 :(得分:1)

看看这三行代码:

class GUIImage(tk.Tk):
    def __init__(self, master, *pargs):

和...

App = GUIImage()

错误消息清楚地说明了这一点:

  

__ init __()缺少1个必需的位置参数:&#39; master&#39;

显然,__init__需要一个名为&#39; master&#39;的参数,您在创建App时无法提供。