0

I tried creating a program that will take in the symptoms of a person and return the disease they have. This is the GUI part of the project.

from tkinter import *
root = Tk()
root.title("Health GUI")
root.geometry("1000x625")

symptoms_list = []
    
def print_symptoms():
    print(symptoms_list)

def typeSymptoms():
    gap3 = Label(text="").pack()
    symptoms_entry = Text(width=50, height=20)
    symptoms_entry.pack()
    symptoms_list.append(symptoms_entry.get(1.0, END))
    done_symptoms = Button(text="I have written my symptoms", width=25, height=5, command=lol)
    done_symptoms.pack()

gap1 = Label(text="").pack()
title = Label(text="HEALTH GUI", font=30).pack()
gap2 = Label(text="").pack()
start_button = Button(text="Click here to start", width=30, height=5, command=typeSymptoms, font=20).pack()

root.mainloop()

Just for simplicity, I tried printing out the symptoms given by the user to the console but it gives me a list with '\n'. Please help. Thanks!(PS: I lerned Tkinter day before yesterday so I don't know much)

Sam_Pam
  • 27
  • 1
  • 4
  • Please provide a [mre]. This exampel just creates a text widget and the command `lol` where I guess your problem might be isnt included. – Thingamabobs Mar 14 '21 at 08:55
  • 1
    Also read [this](https://stackoverflow.com/a/66385069/11106801). – TheLizzard Mar 14 '21 at 09:36
  • Move the `symptom_entry` to outside the function and use `symptoms_entry.get('1.0','end-1c')`. The code flow is wrong, you should consider rewriting this. – Delrius Euphoria Mar 14 '21 at 09:50

1 Answers1

0

At the moment, your variable symptoms_list just holds the contents of the newly created Text widget, since you append this content at startup.

If you want to add the symptoms to the list, you need to have your function lol() that you call when pressing the button.

This function should look something like:

def lol():
    symptoms_text = symptoms_entry.get(1.0, END)
    symptoms_list = symptoms_text.split('\n')
    print_symptoms()

However, your widgets and the symptoms_list would have to be global variables in order for this program to work. It would probably be better, while you are getting acquainted with Tkinter, to learn how to create a dialog as Class with attributes. That makes sharing values between methods so much easier.

Martin Wettstein
  • 2,771
  • 2
  • 9
  • 15