How do I close a form without closing the entire program?

Steve Gronicus at SGA.Ninja
Sun Aug 23 04:40:42 EDT 2020


This program is fully operational with the exception of not being able to
close the form when I have completed the data entry. If I have code for a
second form, both remain visible.
Thoughts appreciated....

================================================================
from tkinter import *

def ShowForm1():
  
  fields1 = ('Sensor_Reading', 'Test_Strip_Reading', 'Dose', 'o2')

  def Data_Entry1(entries1):
   SR = (entries['Sensor_Reading'].get())
   TSR = (entries['Test_Strip_Reading'].get())
   Dose = (entries['Dose'].get())
   o2 = (entries['o2'].get())

  def SubmitForm(entries1):
   SR = entries1['Sensor_Reading'].get()
   TSR = entries1['Test_Strip_Reading'].get()
   Dose = (entries1['Dose'].get())
   o2 = (entries1['o2'].get())
   
   FormDataInfo=open("Form1Data.txt", "w") # Start a new file
   FormDataInfo.write("\n" + "   SR = " + SR + "\n")
   FormDataInfo.write("  TSR = " + TSR + "\n")
   FormDataInfo.write(" Dose = " + Dose + "\n")
   FormDataInfo.write("   o2 = " + o2 + "\n")
   FormDataInfo.close()
   print("Line written to file1")
   
  def makeform1(root, fields1):
   entries1 = {}
   for field1 in fields1:
      row = Frame(root)
      lab = Label(row, width=22, text=field1+": ", anchor='w')
      ent = Entry(row)
      ent.insert(0,"0")
      row.pack(side = TOP, fill = X, padx = 5 , pady = 5)
      lab.pack(side = LEFT)
      ent.pack(side = RIGHT, expand = YES, fill = X)
      entries1[field1] = ent
   return entries1

  if __name__ == '__main__':
   root1 = Tk()
   ents = makeform1(root1, fields1)
   
   b1 = Button(root1, text = 'Submit',
      command=(lambda e = ents: SubmitForm(e)))
   b1.pack(side = LEFT, padx = 5, pady = 5)
 
   b2 = Button(root1, text = 'Quit', command = root1.quit)
   b2.pack(side = LEFT, padx = 5, pady = 5)
   root1.mainloop()
# =======================================================
ShowForm1()
print(" End ")
# =======================================================


Steve
----------------------------------------------------------------

Footnote:
The human brain is one of the most complex things known to man.
according to the human brain.



More information about the Python-list mailing list