试图为我的代码制作一个gui。我做错了什么?

时间:2015-03-28 04:02:30

标签: python-2.7

有一段时间我正在编写一个代码,每当我选择正确的选项时,它会循环并加1或减1,当我选择这样做时,也会打印当前的数字。我现在正试图在Tkinter上制作一个gui。这是原始代码:

students = 0

def addstudent():
    global students
    students = students + 1
    print "\n Student Added"
def subtractstudent():
    global students
    students = students - 1
    print "\n Student Deleted"
def checkstudentrec():
    print students
    print "\n Student Record Found"

ans=True
while ans:
    print ("""
    1.Add a Student
    2.Delete a Student
    3.Look Up Student Record
    4.Exit/Quit
    """)
    ans=raw_input("What would you like to do?")
    if ans=="1": 
        addstudent()
    if ans=="2":
        subtractstudent()
    if ans=="3":
        checkstudentrec()

GUI不起作用:

from TKinter import *


class experiment:

    def __init__(self, master):
        frame = Frame(master)
        frame.pack()

        self.addbutton = Button(frame, text="Add Student", command=self.addstudent)
        self.addbutton.pack(side=LEFT)

        self.subbutton = Button(frame, text="Subtract Student", command=self.subtractstudent)
        self.subbutton.pack(side=LEFT)

        self.checkbutton = Button(frame,text="Check Record", command=self.checkstudentrec)
        self.checkbutton.pack(side=LEFT)

        self.quitButton = Button(frame,text="Quit", command=frame.quit)
        self.quitButton.pack(side=LEFT)

   def addstudent():
        global students
        students = students + 1
        print "\n Student Added"
      def subtractstudent():
         global students
         students = students - 1
         print "\n Student Deleted"
   def checkstudentrec():
        print students
        print "\n Student Record Found"

root = Tk()
students = 0
b = experiment(root)
root.mainloop()

我收到以下错误:

/usr/bin/python2.7 /home/richjtf/PycharmProjects/project1/firstproject.py
File "/home/richjtf/PycharmProjects/project1/firstproject.py", line 8
frame.pack()
^
IndentationError: unexpected indent

Process finished with exit code 1

0 个答案:

没有答案