Python Forum
Second Window can't open due to iExit function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Second Window can't open due to iExit function
#1
Hi,
as soon as I log in and press the Registration-button, the second Window can't open because of the iExit-button.

The Error is:

File "E:/Python/Akustik/Akustik/Pharmacy Login System.py", line 155
Mainframe = Frame(self.master)
^
IndentationError: unindent does not match any outer indentation level

from tkinter import*
import tkinter.messagebox
from tkinter import ttk
import tkinter as tk
import random
import time;
import datetime

def main():
    root = tk.Tk()
    app = Window1(root)
    root.mainloop()
    
class Window1: 
    def __init__(self,master):
        self.master = master
        self.master.title("Pharmacy")
        self.master.geometry('1350x750+0+0')
        self.frame = Frame(self.master)
        self.frame.pack()
        
        
        self.LabelTitle = Label(self.frame, text = 'Pharmacy Management System', 
                                font = ('arial', 50, 'bold'), bd = 20)
        self.LabelTitle.grid(row = 0, column = 0, columnspan = 2, pady = 10)
        
        self.Username = StringVar()
        self.Password = StringVar()
        
        self.Loginframe1 = Frame(self.frame, width = 1010, height = 300, bd = 20,relief = 'ridge')
        self.Loginframe1.grid(row = 1, column = 0)
        
        self.Loginframe2 = Frame(self.frame, width = 1100, height = 100, bd = 20, relief = 'ridge')
        self.Loginframe2.grid(row = 2, column = 0, padx=50)
        
        self.Loginframe3 = Frame(self.frame, width = 1010, height = 200, bd = 10,relief = 'ridge')
        self.Loginframe3.grid(row = 3, column = 0, pady = 2)
        
        
 #------------------------------------------------------------------------------------          
        self.lblUsername = Label(self.Loginframe1, text = 'Username',font = ('arial', 30, 'bold'), bd = 20)                               
        self.lblUsername.grid(row = 0, column = 0)
        self.txtUsername = Entry(self.Loginframe1, text = 'Username', width =15, font = ('arial', 30, 'bold'), bd = 20, textvariable = self.Username)                               
        self.txtUsername.grid(row = 0, column = 1)
        
        self.lblPassword = Label(self.Loginframe1, text = 'Password',  font = ('arial', 30, 'bold'), bd = 20)                               
        self.lblPassword.grid(row = 1, column = 0)
        self.txtPassword = Entry(self.Loginframe1, text = 'Password', width =15,  font = ('arial', 30, 'bold'), bd = 20, show ="*", textvariable = self.Password)                               
        self.txtPassword.grid(row = 1, column = 1)
 #------------------------------------------------------------------------------------       
        
        self.btnLogin = Button(self.Loginframe2, text = "Login", width = 11,font = ('arial', 20, 'bold'),
                                      command = self.Login_System)
        self.btnLogin.grid(row = 0, column = 0)
        
        self.btnReset = Button(self.Loginframe2,text = "Reset", width = 12,font = ('arial', 20, 'bold'),
                                        command = self.Reset)
        self.btnReset.grid(row = 0, column = 1)
        
        self.btnExit = Button(self.Loginframe2,text = "Exit", width = 11,font = ('arial', 20, 'bold'),
                                        command = self.Exit)
        self.btnExit.grid(row = 0, column = 2)
        
  #------------------------------------------------------------------------------------         
        
        self.btnRegistration = Button(self.Loginframe3, text = "Registration", 
                                      state = DISABLED, command = self.registration_window,font = ('arial', 20, 'bold'))
        self.btnRegistration.grid(row = 0, column = 0, pady=5, padx=77)
        
        self.btnHospital = Button(self.Loginframe3,text = "Hospital", 
                                         state = DISABLED, command = self.hospital_window,font = ('arial', 20, 'bold'))
        self.btnHospital.grid(row = 0, column = 1, pady=5, padx=77)
  #------------------------------------------------------------------------------------      
    def Login_System(self):
        user = (self.Username.get())
        pas = (self.Password.get())
        
        if user == str(1) and pas == str(2):
            self.btnRegistration.config(state = NORMAL)
            self.btnHospital.config(state = NORMAL)
        else:
            tkinter.messagebox.showinfo("Pharmacy Management System","You have entered an invalid input!")
            self.btnRegistration.config(state = DISABLED )
            self.btnHospital.config(state = DISABLED )
            self.Username.set("")
            self.Password.set("")
            self.txtUsername.focus()
    
    def Reset(self):
        self.btnRegistration.config(state = DISABLED )
        self.btnHospital.config(state = DISABLED )
        self.Username.set("")
        self.Password.set("")
        self.txtUsername.focus()
    
    def Exit(self):
        result = tkinter.messagebox.askyesno("Pharmacy Management System","Are you sure?")
        if result == True:
            self.master.destroy()
            return
                

  #--------------------------------------------open new Window ----------------------------------------        
    
    def registration_window(self):
        self.newWindow = Toplevel(self.master)
        self.app = Window2(self.newWindow)
        
    def hospital_window(self):
        self.newWindow = Toplevel(self.master)
        self.app = Window3(self.newWindow)
        
class Window2: 
    def __init__(self,master):
        self.master = master
        self.master.title("Registration")
        self.master.geometry('1350x750+0+0')
        self.frame = Frame(self.master)
        self.frame.pack()   
        
        DateofOrder = StringVar()
        DateofOrder.set(time.strftime("%d/%m/%Y"))
        
        var1 = StringVar()
        var2 = StringVar()
        var3 = StringVar()
        var4 = IntVar()
        
        Firstname = StringVar()
        Surname = StringVar()
        Address = StringVar()
        PostCode = StringVar()
        Telephone = StringVar()
        Ref = StringVar()
        
        Membership = StringVar()
        Membership.set("0")
        
        
#--------------------------------------Functions Declared--------------------------------------------
  
    def iExit(self):
         result = tkinter.messagebox.askyesno("Club Member Registration System", "Confirm if you want to exit.")
         if result == True:
            self.master.destroy()
            return
#    def iExit():
#         iExit = tkinter.messagebox.askyesno("Club Member Registration System", "Confirm if you want to exit.")
#         if iExit > 0:
#             root.destroy()
#             return
        
#--------------------------------------Frames--------------------------------------------
        
        Mainframe = Frame(self.master)
        Mainframe.pack()
        
        TitleFrame = Frame(Mainframe, bd = 20, width = 1350, padx = 26, relief = RIDGE)
        TitleFrame.pack(side = TOP)
        
        self.lblTitle = Label(TitleFrame,font = ('arial',50,'bold'),text = "Member Registration", padx = 2)
        self.lblTitle.grid()

#----------------------------------------Lower Frames--------------------------------------------

        MemberDetailsFrame = LabelFrame(Mainframe, width = 1350, height = 500, bd = 20,
                                        pady = 5, relief = RIDGE)
        MemberDetailsFrame.pack(side = BOTTOM)
        
        FrameDetails = LabelFrame(MemberDetailsFrame, bd = 10, width = 800, height = 400, relief = RIDGE)
        FrameDetails.pack(side = LEFT)
        
        MembersName_F = LabelFrame(FrameDetails, bd = 10, width = 350, height = 400,
                                   font = ('arial', 12, 'bold'), text = 'Customer Name', relief = RIDGE)
        MembersName_F.grid(row = 0, column = 0)
        
        Receipt_ButtonFrame = LabelFrame(MemberDetailsFrame, bd = 10, width = 1000, height = 400,
                                         relief = RIDGE)
        Receipt_ButtonFrame.pack(side = RIGHT)


#------------------------------------------------------------------------------------
        self.lblReferenceNo = Label(MembersName_F,font = ('arial',15,'bold'),text = "Reference No", bd = 7)
        self.lblReferenceNo.grid(row = 0, column = 0, sticky =W)
        self.txtReferenceNo = Entry(MembersName_F,font = ('arial',15,'bold'), bd = 7, textvariable = Ref,
                                    state = DISABLED, insertwidth = 2)
        self.txtReferenceNo.grid(row = 0, column = 1)
        
        self.lblFirstname = Label(MembersName_F,font = ('arial',15,'bold'),text = "Firstname", bd = 7)
        self.lblFirstname.grid(row = 1, column = 0, sticky =W)
        self.txtFirstname = Entry(MembersName_F,font = ('arial',15,'bold'), bd = 7, insertwidth = 2, textvariable = Firstname)
        self.txtFirstname.grid(row = 1, column = 1)
        
        self.lblSurname = Label(MembersName_F,font = ('arial',15,'bold'),text = "Surname", bd = 7)
        self.lblSurname.grid(row = 2, column = 0, sticky =W)
        self.txtSurname = Entry(MembersName_F,font = ('arial',15,'bold'), bd = 7, insertwidth = 2, textvariable = Surname)
        self.txtSurname.grid(row = 2, column = 1)
        
        self.lblAddress = Label(MembersName_F,font = ('arial',15,'bold'),text = "Address", bd = 7)
        self.lblAddress.grid(row = 3, column = 0, sticky =W)
        self.txtAddress = Entry(MembersName_F,font = ('arial',15,'bold'), bd = 7, insertwidth = 2, textvariable = Address)
        self.txtAddress.grid(row = 3, column = 1)
        
        self.lblPostCode = Label(MembersName_F,font = ('arial',15,'bold'),text = "PostCode", bd = 7)
        self.lblPostCode.grid(row = 4, column = 0, sticky =W)
        self.txtPostCode = Entry(MembersName_F,font = ('arial',15,'bold'), bd = 7, insertwidth = 2, textvariable = PostCode)
        self.txtPostCode.grid(row = 4, column = 1)
        
        self.lblTelephone = Label(MembersName_F,font = ('arial',15,'bold'),text = "Telephone", bd = 7)
        self.lblTelephone.grid(row = 5, column = 0, sticky =W)
        self.txtTelephone = Entry(MembersName_F,font = ('arial',15,'bold'), bd = 7, insertwidth = 2, textvariable = Telephone)
        self.txtTelephone.grid(row = 5, column = 1)
        
        self.lblDate = Label(MembersName_F,font = ('arial',15,'bold'),text = "Date", bd = 7)
        self.lblDate.grid(row = 6, column = 0, sticky =W)
        self.txtDate = Entry(MembersName_F,font = ('arial',15,'bold'), bd = 7, insertwidth = 2, textvariable = DateofOrder)
        self.txtDate.grid(row = 6, column = 1)
        
#-------------------------------------------Member Information-------------------------------------------

        self.lblProve_of_ID = Label(MembersName_F, font = ('arial', 14, 'bold'), text = "Prove of ID", bd = 7)
        self.lblProve_of_ID.grid(row = 7, column = 0, sticky = W)
        
        self.cboProve_of_ID = ttk.Combobox(MembersName_F, textvariable = var1, state = 'readonly',
                                           font = ('arial', 14, 'bold'), width = 19)
        self.cboProve_of_ID ['value'] = ('', 'Pilot Licence', 'Driving Licence', 'Passport', 'Student ID')
        self.cboProve_of_ID.current(0)
        self.cboProve_of_ID.grid(row = 7, column = 1)
        
        
        self.lblType_of_Member = Label(MembersName_F, font = ('arial', 14, 'bold'), text = "Type_of_Member", bd = 7)
        self.lblType_of_Member.grid(row = 8, column = 0, sticky = W)
        
        self.cboType_of_Member = ttk.Combobox(MembersName_F, textvariable = var2, state = 'readonly',
                                           font = ('arial', 14, 'bold'), width = 19)
        self.cboType_of_Member ['value'] = ('', 'Full Member', 'Annual Membership', 'Pay As You Go', 'Honorary Member')
        self.cboType_of_Member.current(0)
        self.cboType_of_Member.grid(row = 8, column = 1)
        
        
        
        self.lblMethod_of_Payment = Label(MembersName_F, font = ('arial', 14, 'bold'), text = "Method_of_Payment", bd = 7)
        self.lblMethod_of_Payment.grid(row = 9, column = 0, sticky = W)
        
        self.cboMethod_of_Payment = ttk.Combobox(MembersName_F, textvariable = var3, state = 'readonly',
                                           font = ('arial', 14, 'bold'), width = 19)
        self.cboMethod_of_Payment ['value'] = ('', 'Visa Card', 'Master Card', 'Debit Card', 'Cash')
        self.cboMethod_of_Payment.current(0)
        self.cboMethod_of_Payment.grid(row = 9, column = 1)
        
#-------------------------------------------Check Button-------------------------------------------
       
        self.chkMembership = Checkbutton(MembersName_F, text = "Membership Fees", variable = var4, onvalue = 1,
                                         offvalue = 0, font = ('arial', 16, 'bold')).grid(row = 10, column = 0, sticky = W)
        self.txtMembership = Entry (MembersName_F, font =('arial', 14, 'bold'), textvariable = Membership, bd = 7,
                                    insertwidth = 2, state = DISABLED, justify = RIGHT )
        self.txtMembership.grid (row = 10, column = 1)
 
#-------------------------------------------Receipt-------------------------------------------
       
        self.lblLabel = Label(Receipt_ButtonFrame, font = ('arial', 14, 'bold'), 
                              text = "Member Ref\t Firstname\t Surname\t Address\t\t Date Reg.\t Telephone\t Member Paid", bd = 7)
        self.lblLabel.grid(row = 0, column = 0, columnspan = 4)
        
        self.txtReceipt = Text(Receipt_ButtonFrame, width = 112, height = 22, font = ('arial', 14, 'bold'), pady = 10, bd = 7)
        self.txtReceipt.grid(row = 1, column = 0, columnspan = 4)

#-------------------------------------------Buttons-------------------------------------------

        self.btnReceipt = Button(Receipt_ButtonFrame, padx = 18, bd = 7, font = ('arial', 16, 'bold'), width = 13, text = "Receipt")
        self.btnReceipt.grid(row = 2, column = 0)
        self.btnReset = Button(Receipt_ButtonFrame, padx = 18, bd = 7, font = ('arial', 16, 'bold'), width = 13, text = "Reset")
        self.btnReset.grid(row = 2, column = 1)
        self.btnExit = Button(Receipt_ButtonFrame, padx = 18, bd = 7, font = ('arial', 16, 'bold'), width = 13, text = "Exit", command = self.iExit)
        self.btnExit.grid(row = 2, column = 2)
        
        
        
class Window3: 
    def __init__(self,master):
        self.master = master
        self.master.title("Hospital")
        self.master.geometry('1350x750+0+0')
        self.frame = Frame(self.master)
        self.frame.pack()
        
#--------------------------------------------------------------------------------------
        
if __name__ == '__main__':
    main()
Reply
#2
Please always show the entire, unedited error traceback (within error tags), what looks like gobbledygook is actually vary useful information
Reply
#3
Ok sorry, do you mean this:

Error:
runfile('E:/Python/Akustik/Akustik/Test.py', wdir='E:/Python/Akustik/Akustik') Traceback (most recent call last): File "E:\Anaconda\Anacon\lib\site-packages\IPython\core\interactiveshell.py", line 3325, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-45-a5ed1627d79e>", line 1, in <module> runfile('E:/Python/Akustik/Akustik/Test.py', wdir='E:/Python/Akustik/Akustik') File "E:\Anaconda\Anacon\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile execfile(filename, namespace) File "E:\Anaconda\Anacon\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "E:/Python/Akustik/Akustik/Test.py", line 155 Mainframe = Frame(self.master) ^ IndentationError: unindent does not match any outer indentation level
Reply
#4
Quote:Ok sorry, do you mean this:
Yes, (I correct tag type to error)
The problem is actually lines 143 and 144, which are indented one space too many.
Fix that and it runs fine.
Reply
#5
Ah ok, I got it, thanks!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 346 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Now if window is open or not delcencen 5 1,582 Mar-25-2023, 07:26 PM
Last Post: deanhystad
  [PyQt] Hover over highlighted text and open popup window DrakeSoft 2 1,450 Oct-29-2022, 04:30 PM
Last Post: DrakeSoft
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,832 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  Subprocess window won't open on Mac blakefindlay 1 2,134 Feb-06-2021, 04:23 AM
Last Post: deanhystad
  function in new window (tkinter) Dale22 7 4,966 Nov-24-2020, 11:28 PM
Last Post: Dale22
  tkinter window and turtle window error 1885 3 6,624 Nov-02-2019, 12:18 PM
Last Post: 1885
  How to stop a tkinter function, without closing the window? keakins 5 12,949 Jun-29-2017, 11:53 AM
Last Post: keakins
  update a variable in parent window after closing its toplevel window gray 5 8,978 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020