0

So I'm trying to print the contents of the text widget that the user inputs. I used the .get() but it doesn't work. It asks me to add index or something but Im not sure how to do that. You will see that I used the .get() method for the rest of the widgets and it worked fine. Help will be highly appreciated and the whole code is below.

import tkinter as tk  #importing the tkinter library to start making GUI


def printAlldetails():
    print("Those are the details related to",namebox.get(),":")
    print("Name:", namebox.get())
    print("Age:", agebox.get())
    print("Blood type:", bloodtypebox.get())
    print("Weight:", weightbox.get())
    print("Height:", heightbox.get())
    print("Whatever written:", anythingbox.get())



#creating the window
window = tk.Tk()


#add a greeting
greeting = tk.Label(text ="Welcome to the first GUI i make alone")
greeting.grid(column = 1, row=1)

#ask to enter information
ask = tk.Label(text ="Please enter the following information :")
ask.grid(column= 1, row=2)

#ask for name
name = tk.Label(text="Name:")
name.grid(column = 1, row = 3)

#entry box for name
namebox = tk.Entry()
namebox.grid(column = 2, row = 3)

#ask for age
age = tk.Label(text="Age:")
age.grid(column = 1, row = 4)


#entry box for age
agebox = tk.Entry()
agebox.grid(column =2, row = 4)


#ask for bloodtype
bloodType = tk.Label(text="Blood type:")
bloodType.grid(column = 1, row = 5)

#entry box for bloodtype
bloodtypebox = tk.Entry()
bloodtypebox.grid(column = 2, row = 5)


#ask for weight
weight = tk.Label(text="Weight:")
weight.grid(column = 1, row = 6)

#entry box for weight
weightbox = tk.Entry()
weightbox.grid(column = 2, row = 6)


#ask for height
height = tk.Label(text="Height:")
height.grid(column = 1, row = 7)

#entry box for height
heightbox = tk.Entry()
heightbox.grid(column = 2, row = 7)


#write anything label
anything = tk.Label(text="Write whatever you want:")
anything.grid(column =1, row = 8)


#write anything entry box
anythingbox = tk.Text()
anythingbox.grid(column =2, row = 8)


#button for showing details
button1 = tk.Button(text = "Show Details", command= printAlldetails)
button1.grid(column = 1, row = 9)

#button for canceling
button1 = tk.Button(text = "Close", command= quit)
button1.grid(column = 2, row = 9)





#to keep the window open and not close
window.mainloop()

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
AAA
  • 1

0 Answers0