import tkinter as tk
import datetime
import Inputs
import os
today = datetime.datetime.now()
today = today.strftime("%Y%m%d%H%M%S")
root = tk.Tk()
root.geometry("500x600")
root.title("General Examination of the Patient")
bp = tk.StringVar()
def submited():
new_file = f"{Inputs.name.get()}_trial"
path = Inputs.path
fullpath = os.path.join(path, new_file)
with open(fullpath, "w") as gpe:
gpe.write(bp.get() + "\n")
root.quit()
print(bp.get())
ga_label = tk.Label(root, text="GA")
bp_label = tk.Label(root, text="Blood Pressure")
ga_label.grid(columnspan=3, row=0)
bp_label.grid(column=0, row=1)
bp_entry = tk.Entry(root, textvariable=bp)
bp_entry.grid(column=1, row=1)
submit_btn = tk.Button(root, text="Submit", command=submited)
submit_btn.grid(columnspan=2, row=6)
root.mainloop()
I have tried to find my error for more than three hours. I am a complete newbie so please be patient with me.
so far, my files are getting created, but the file does not contain any of the data I am trying to write in them. even in the console output my bp.get() is not returning any value.
Just few days back I used this same format of code to get another similar app working but this does not work. Please help!
As requested here is the Inputs.py file code:
import datetime
import tkinter as tk
import os
import datetime
today = datetime.datetime.now()
today = today.strftime("%Y%m%d%H%M%S")
# today = str(today)
basicdetails = tk.Tk()
# Basic patient details
name = tk.StringVar(basicdetails, value="Name")
age = tk.StringVar()
gender = tk.StringVar()
height = tk.StringVar()
weight = tk.StringVar()
diet = tk.StringVar()
ethnicity = tk.StringVar()
occupation = tk.StringVar()
residence = tk.StringVar()
contact = tk.StringVar()
path = ""
def submit():
global path
new_file = f"{name.get()}_basicdetails_{today}"
path = f"E:/PythonProjects/ambiproj/Data/{name.get()}_{today}"
try:
os.mkdir(path)
except FileExistsError:
pass
fullpath = os.path.join(path, new_file)
with open(fullpath, "w") as s:
s.write(name.get() + "\n")
s.write(age.get() + "\n")
s.write(gender.get() + "\n")
s.write(height.get() + "\n")
s.write(weight.get() + "\n")
s.write(occupation.get() + "\n")
s.write(ethnicity.get() + "\n")
s.write(residence.get() + "\n")
s.write(contact.get() + "\n")
basicdetails.quit()
# Page 1: Basic Details
# name = tk.StringVar(root, value="Name")
# age = tk.StringVar()
# gender = tk.StringVar()
# height = tk.StringVar()
# weight = tk.StringVar()
# diet = tk.StringVar()
# ethnicity = tk.StringVar()
# occupation = tk.StringVar()
# residence = tk.StringVar()
# contact = tk.StringVar()
# Page 2: Additional details (to be entered later)
namebox = tk.Entry(basicdetails, textvariable=name).grid(row=0, column=1)
agebox= tk.Entry(basicdetails, textvariable=age).grid(row=1, column=1)
genderbox = tk.Entry(basicdetails, textvariable=gender).grid(row=2, column=1)
heighbox = tk.Entry(basicdetails, textvariable=height).grid(row=3, column=1)
weightwb = tk.Entry(basicdetails, textvariable=weight).grid(row=4, column=1)
dietbox = tk.Entry(basicdetails, textvariable=diet).grid(row=5, column=1)
ethnicitybox = tk.Entry(basicdetails, textvariable=ethnicity).grid(row=6, column=1)
occubox = tk.Entry(basicdetails, textvariable=occupation).grid(row=7, column=1)
contactbox = tk.Entry(basicdetails, textvariable=contact).grid(row=8, column=1)
submitbut = tk.Button(basicdetails, text="Submit", font="Verdana", command=submit).grid(row=9, columnspan=2)
basicdetails.mainloop()
# .............................