有人可以帮我找出代码中的错误吗? (Python基本GUI)

我直到最近才将脚趾浸入python(仅使用Java和JS编码),并认为我会尝试制作简单的数字键盘GUI。我仍然习惯于缩进格式。

我的代码返回以下错误

"  File "/home/pi/Desktop/Lab Work/Lab 1/Number Pad test GUI.py", line 6
    x,y = self.winfo_width(), self.winfo_height()
    ^
SyntaxError: unexpected indent"
import tkinter, tkinter.ttk as ttk
import random

class BaseWindow(tkinter.tk):
    def_change (self)
        x,y = self.winfo_width(), self.winfo_height()

        self.minimize (x,y)
        #This locks window size when called

    def FgridFormatButtons (self, ButtonList, NewLineAmount = 3):
        self.Row = 0
        self.Col = 0

        for Button in ButtonList:
            Button.grid(row = self.Row, column = self.Col)

            self.Col += 1

            if self.Col == NewLineAmount:
                self.Row += 1
                self.Col = 0
                continue

class Window (BaseWindow):
    def __init__(self, **args):
        super(Window, self).__init__()

        #Main method code

        self.EntryFrame = ttk.Frame(self)
        self.PadFrame = ttk.Frame(self)

        self.EntryFrame.pack(padx = 5, pady = 5)
        self.PadFrame.pack(padx = 5, pady = 5)

        self.AllButtons = []
        self.CanWrite = true

        self.Cod = args.get("Code") or random.randrange(9999)
        self.Timer = args.get("Timer") or 2000

        print ("debug %d"% self.Code)

        for x in range (1,10):
            self.AllButtons.append(ttk.Button(self.PadFrame, width = 4, text = x, command = lambda y = x: self.Update(x)))
            self.bind(str(x), lambda CatchEvent, y = x: self.Update(y))

        self.FGridFormatButtons(self.AllButtons)

        self.ZeroButton = ttk.Button (self.PadFrame, width = 4, text = 0, command = lambda: self.Update(0))
        self.SubmitButton = ttk.Button(self.PadFrame, width = 4, text = "Ent", command = self.CheckCode)
        self.ClearButton = ttk.Button(self.PadFrame, width = 4, text = "C", command = lambda: self.Update(-1))

        self.ClearButton.grid(row = self.Row, column = 0)
        self.ZeroButton.grid(row = self.Row, column = 1)
        self.SubmitButton.grid(row = self.Row, column = 2)

        self.bind ("0", lambda CatchEvent: self.Update(0))
        self.bind("<return>" lambda CatchEvent: self.CheckCode())

        self.KeyEnter = ttk.Entry(self,EntryFrame, state ="disabled")
        self.KeyEnter.pack

        #--
        self.after (5, self._Change)
        #This will wait 5 miliseconds and then lock the window
        #If your computer takes longer than 5 miliseconds to load then kill yourself. Or alternatively, change the last value to match how long it takes

def Update (self, x):
    if self.CanWrite:
        self.KeyEnter["state"] = "normal"

        if x == 1:
            self.KeyEnter.delete(0, tkinter.END)
        else:
            self.KeyEnter.insert(tkinter.END, x)

        self.KeyEnter["state"] = 'disabled'

def CheckCode(self):
    Key = self.KeyEnter.get()

    self.Update(-1)

    if key == str(self.Code):
        self.Update("Correct Code!")
        self.;after(self.Timer, self.destroy)

    else:
        self.Update("Incorrect code")

    self.ChangeWritePerms()

    self.after(self.Timer, self.ChangeWritePerms)

def ChangeWritePerms(self):
    if self.CanWrite:
        self.CanWrite = False
    else:
        self.CanWrite = True
        self.Update(-1)


window().mainloop()


class BaseWindow(tkinter.tk):
    def_change (self)
        x,y = self.winfo_width(), self.winfo_height()

        self.minimize (x,y)
        #This locks window size when called

    def FgridFormatButtons (self, ButtonList, NewLineAmount = 3):
        self.Row = 0
        self.Col = 0

        for Button in ButtonList:
            Button.grid(row = self.Row, column = self.Col)

            self.Col += 1

            if self.Col == NewLineAmount:
                self.Row += 1
                self.Col = 0
                continue

class Window (BaseWindow):
    def __init__(self, **args):
        super(Window, self).__init__()

        #Main method code

        self.EntryFrame = ttk.Frame(self)
        self.PadFrame = ttk.Frame(self)

        self.EntryFrame.pack(padx = 5, pady = 5)
        self.PadFrame.pack(padx = 5, pady = 5)

        self.AllButtons = []
        self.CanWrite = true

        self.Cod = args.get("Code") or random.randrange(9999)
        self.Timer = args.get("Timer") or 2000

        print ("debug %d"% self.Code)

        for x in range (1,10):
            self.AllButtons.append(ttk.Button(self.PadFrame, width = 4, text = x, command = lambda y = x: self.Update(x)))
            self.bind(str(x), lambda CatchEvent, y = x: self.Update(y))

        self.FGridFormatButtons(self.AllButtons)

        self.ZeroButton = ttk.Button (self.PadFrame, width = 4, text = 0, command = lambda: self.Update(0))
        self.SubmitButton = ttk.Button(self.PadFrame, width = 4, text = "Ent", command = self.CheckCode)
        self.ClearButton = ttk.Button(self.PadFrame, width = 4, text = "C", command = lambda: self.Update(-1))

        self.ClearButton.grid(row = self.Row, column = 0)
        self.ZeroButton.grid(row = self.Row, column = 1)
        self.SubmitButton.grid(row = self.Row, column = 2)

        self.bind ("0", lambda CatchEvent: self.Update(0))
        self.bind("<return>" lambda CatchEvent: self.CheckCode())

        self.KeyEnter = ttk.Entry(self,EntryFrame, state ="disabled")
        self.KeyEnter.pack

        #--
        self.after (5, self._Change)
        #This will wait 5 miliseconds and then lock the window
        #If your computer takes longer than 5 miliseconds to load then kill yourself. Or alternatively, change the last value to match how long it takes

def Update (self, x):
    if self.CanWrite:
        self.KeyEnter["state"] = "normal"

        if x == 1:
            self.KeyEnter.delete(0, tkinter.END)
        else:
            self.KeyEnter.insert(tkinter.END, x)

        self.KeyEnter["state"] = 'disabled'

def CheckCode(self):
    Key = self.KeyEnter.get()

    self.Update(-1)

    if key == str(self.Code):
        self.Update("Correct Code!")
        self.;after(self.Timer, self.destroy)

    else:
        self.Update("Incorrect code")

    self.ChangeWritePerms()

    self.after(self.Timer, self.ChangeWritePerms)

def ChangeWritePerms(self):
    if self.CanWrite:
        self.CanWrite = False
    else:
        self.CanWrite = True
        self.Update(-1)

window().mainloop()
评论