Hope you are doing well! I still do my medical things and again, I faced the new problem.
I have the label in the main window and I need to modify it based on input.
It works perfectly if I have both functions(see below) stored in the same window.(Submit button works if I enter only Hb)
But if I make a function that opens the new window (window2 in this case) and try to click my only checkbutton there (Back pain in this case): back_paint.get() can not be passed and stored in window1 even if I make it global. I would appreciate if you could take a look at the code below! Thank you!
p.s. Putting these 2 functions in the same window is not a solution. I need separate window2 where user can put his symptoms and based on that labels in window1 modify themselves.
import tkinter as tk
window=tk.Tk()
window.geometry("300x200")
window.resizable(width=False, height=False)
#create main entry spot
label_Hb=tk.Label(text="Enter Hb")
Hb=tk.Entry()
label_Hb.grid(row=0, column=0)
Hb.grid(row=0, column=1)
#create the label I need to modify
answer=tk.Label(text="")
answer.grid(row=1, column=0)
#create the function for @Symptoms@ button
def symptoms():
global window2
window2=tk.Tk()
window2.geometry("100x100")
window2.resizable(width=False, height=False)
global back_pain
back_pain=tk.IntVar()
back_pain_btn=tk.Checkbutton(master=window2,text="Back pain", onvalue=1, offvalue=0, variable=back_pain)
back_pain_btn.pack()
#create the main function for @Submit@ button
def submit():
if float(Hb.get())<12:
answer.config(text="Anemia")
if back_pain.get():
answer.config(text='Possible malignancy')
#create the button that modifies the label above
submit_btn=tk.Button(text="Submit", command=submit)
submit_btn.grid(row=2, column=0)
#create the button that opens additional symptoms window
symptoms=tk.Button(text="Symptoms", command=symptoms)
symptoms.grid(row=2, column=1)
window.mainloop()
I tried to make the variable in window2 global since this is the only way that came to my mind.