简体   繁体   中英

Why do I get TypeError: __init__() missing 1 required positional argument: 'master' in Python

I got:

__init__() missing 1 required positional argument: 'master'

I don't know what's the problem. This is my code:

from tkinter import*
class minigame():
def __init__(self,master):
    self.master=master
    self.master.title("try")
    self.lbl1=Label(self.master)
    self.lbl1['text']="User Name"
    self.lbl1.grid(row=1,column=1)
    self.txt1=Entry(self.master)
    self.txt1['width']=30
    self.txt1.grid(row=1,column=2)
    self.b4=Button(self.master,text="start",command=mulai)
    self.b4.grid(row=2,column=2)
class mulai():
def __init__(self,master):
    self.win=master
    self.win.title('MINIGAME')
    self.asal()
def asal(self):
    self.masteer.withdraw()
    self.tk=Toplevel(self.master)
    self.radi(self.tk)
def start(self):
    self.var=IntVar()
    self.pilihan="Anda Menjawab" +str(var.get())
def radi(self):
    var=self.start
    rb1=Radiobutton(self.master,text="Martha",variable=self.var,value=0,command=self.start)
    rb1.grid(row=1)
    rb2=Radiobutton(self.master,text="Kula Diamond",variable=self.var,value=1,command=self.start)
    rb2.grid(row=2)
    self.label=Label(self.master,text="WHO IS THE BEST WAIFU?")
    self.label.grid(row=0)
if __name__ == '__main__':
    root=Tk()
    app=minigame(root)

What's wrong?

self.b4=Button(self.master,text="start",command=mulai)

you can use a function in the command, the function will launch the class, giving the root as parameter.

self.b4=Button(self.master,text="start",command=self.launch_mulai)

def launch_mulai(self, *arg):
   mulai(self.master)

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