I'm trying to make this program end straight away without asking the question " The program is still running,Do you want to kill it? " if the wrong password entered for the third time. Tried using 'quit()' but the program become not responding. Please help me.
import Tkinter
global root
global s
# this is the main/root window
root = Tkinter.Tk()
root.title("Stock Plus system")
root.geometry('800x600')
b2Var=Tkinter.StringVar()
s = 1
def win2():
# this is the child window
labelcementin = Tkinter.Label(root,text='Cement quantity in:')
labelcementin.grid(row=1,column=1)
labelhammerin = Tkinter.Label(root,text='Hammer quantity in;')
labelhammerin.grid(row=2,column=1)
labelspannerin = Tkinter.Label(root,text='Spanner quantity in:')
labelspannerin.grid(row=3,column=1)
labelbrickin = Tkinter.Label(root,text='Brick quantity in:')
labelbrickin.grid(row=4,column=1)
labelmirrorin = Tkinter.Label(root,text='Mirror quantity in:')
labelmirrorin.grid(row=5,column=1)
labelcementout = Tkinter.Label(root,text='Cement quantity out:')
labelcementout.grid(row=1,column=3)
labelhammerout = Tkinter.Label(root,text='Hammer quantity out:')
labelhammerout.grid(row=2,column=3)
labelspannerout = Tkinter.Label(root,text='Spanner quantity out:')
labelspannerout.grid(row=3,column=3)
labelbrickout = Tkinter.Label(root,text='Brick quantity out:')
labelbrickout.grid(row=4,column=3)
labelmirrorout = Tkinter.Label(root,text='Mirror quantity out:')
labelmirrorout.grid(row=5,column=3)
def calc_val():
Total_StockIn=int(cementinVar.get())+int(hammerinVar.get())+int(spannerinVar.get())+int(brickinVar.get())+int(mirrorinVar.get())
StockInLabel=Tkinter.Label(root,text='The total stock in is '+str(Total_StockIn))
StockInLabel.grid(row=8,column=2)
Total_Expenses= (int(cementinVar.get())*16)+(int(hammerinVar.get())*10)+(int(spannerinVar.get())*8)+(int(brickinVar.get())*2)+(int(mirrorinVar.get())*22)
ExpensesLabel=Tkinter.Label(root,text='The total expenses is RM ' + str(Total_Expenses))
ExpensesLabel.grid(row=9,column=2)
Total_Income= (int(cementoutVar.get())*18)+(int(hammeroutVar.get())*12)+(int(spanneroutVar.get())*10)+(int(brickoutVar.get())*4)+(int(mirroroutVar.get())*25)
IncomeLabel = Tkinter.Label(root,text = 'The Total income is RM ' +str(Total_Income))
IncomeLabel.grid(row=8, column= 4)
Remaining_Stock =Total_StockIn-(int(cementoutVar.get())+int(hammeroutVar.get())+int(spanneroutVar.get())+int(brickoutVar.get())+int(mirroroutVar.get()))
RemainingLabel = Tkinter.Label(root,text = 'The remaining stock is ' + str(Remaining_Stock))
RemainingLabel.grid(row=9, column = 4)
Total_Profit = (Total_Income) - (Total_Expenses)
ProfitLabel = Tkinter.Label(root,text = 'The total profit is RM ' + str(Total_Profit))
ProfitLabel.grid(row=10, column = 3)
quit()
boxcementin = Tkinter.Entry(root,width=12,textvariable=cementinVar)
boxcementin.grid(row=1, column=2)
boxhammerin = Tkinter.Entry(root,width=12,textvariable=hammerinVar)
boxhammerin.grid(row=2, column=2)
boxspannerin = Tkinter.Entry(root,width=12,textvariable=spannerinVar)
boxspannerin.grid(row=3, column=2)
boxbrickin = Tkinter.Entry(root,width=12,textvariable=brickinVar)
boxbrickin.grid(row=4, column=2)
boxmirrorin = Tkinter.Entry(root,width=12,textvariable=mirrorinVar)
boxmirrorin.grid(row=5, column=2)
boxcementout = Tkinter.Entry(root,width=12,textvariable=cementoutVar)
boxcementout.grid(row=1, column=4)
boxhammerout = Tkinter.Entry(root,width=12,textvariable=hammeroutVar)
boxhammerout.grid(row=2, column=4)
boxspannerout = Tkinter.Entry(root,width=12,textvariable=spanneroutVar)
boxspannerout.grid(row=3, column=4)
boxbrickout = Tkinter.Entry(root,width=12,textvariable=brickoutVar)
boxbrickout.grid(row=4, column=4)
boxmirrorout = Tkinter.Entry(root,width=12,textvariable=mirroroutVar)
boxmirrorout.grid(row=5, column=4)
button = Tkinter.Button(root,text='Calculate',command=calc_val)
button.grid(row=7,column=3)
def textboxvalue():
#For password entry
global s
if (s!=3 ):
Password=b2Var.get()
Username=b1Var.get()
if Password ==('stock123'):
label4=Tkinter.Label(root,text='Welcome to stock plus system, press login again to start using')
label4.grid(row=0,column=3)
Button_1 = Tkinter.Button(root, text="Login", command=win2)
Button_1.grid(row=7,column=3)
else:
s =s+1
label3=Tkinter.Label(root,text='Try again')
label3.grid(row=3,column=1)
else:
label5=Tkinter.Label(root,text='bye')
label5.grid(row=4,column=4)
label6=Tkinter.Label(root,text='Thank You for using Stock Plus System ')
label6.grid(row=5,column=4)
#Widgets in main window
Button_1 = Tkinter.Button(root, text="Login", command=textboxvalue)
Button_1.grid(row=7, column=3)
b1Var = Tkinter.StringVar()
b2Var = Tkinter.StringVar()
box1Label = Tkinter.Label(root,text='Username:')
box1Label.grid(row=1,column=3)
box2Label = Tkinter.Label(root,text='Password:')
box2Label.grid(row=2,column=3)
box1Text = Tkinter.Entry(root,textvariable=b1Var,width=12)
box1Text.grid(row=1, column=4)
box2Text = Tkinter.Entry(root,textvariable=b2Var,width=12,show='*')
box2Text.grid(row=2, column=4)
cementinVar = Tkinter.IntVar()
hammerinVar = Tkinter.IntVar()
spannerinVar = Tkinter.IntVar()
brickinVar = Tkinter.IntVar()
mirrorinVar = Tkinter.IntVar()
cementoutVar = Tkinter.IntVar()
hammeroutVar = Tkinter.IntVar()
spanneroutVar = Tkinter.IntVar()
brickoutVar = Tkinter.IntVar()
mirroroutVar = Tkinter.IntVar()
root.mainloop()
quit(), instead of just telling us you tried it? Also, can you give us a complete minimal example instead of a fragment?something.destroy(), but I can't tell that from what you've shown us (or guess what thatsomethingneeds to be; mayberoot, but I can't be sure).quit()from application-type code. For command-line programs, usesys.exit(). For Tkinter GUIs, call thequitmethod on the appropriate window, usuallyroot.quit(). That probably won't solve your whole problem, but it may solve the "not responding" one.