How to print and enter user input in a text box in tkinter, Python 3.2.5?

I am completely new to Python and I just wrote a short code code that prints and requests input in the python shell. It works like a diary, where it asks for a date, and then prints entries for that date. I was hoping to include this call and response in a text box in the tkinter GUI. I am wondering how to get this bit of code to execute in a text field, and not in a python shell.

month = int(float(input("Month(MM): "))) day = int(float(input("Day(DD): "))) year = int(float(input("Year(YYYY): "))) print(str(month)+"/"+str(day)+"/"+str(year)) noEntry = True if month == 1 and day == 2 and year == 3456: noEntry = False print("Text") if month == 7 and day == 8 and year == 9012: noEntry = False print("More Text") if noEntry: print("No Entry Found") 

I would also like to avoid calling this code as an external file. I want to know how to implement this code in the tkinter GUI text box, and not how to get the file containing this code. Mostly because it is such a short program and it seems unnecessary. Thanks for the help in advance!

+4
source share
2 answers

Here is the Tk base window, which will receive data for the month, day, and year.

 from Tkinter import * root = Tk() label1 = Label( root, text="Month(MM)") E1 = Entry(root, bd =5) label2 = Label( root, text="Day(DD)") E2 = Entry(root, bd =5) label3 = Label( root, text="Year(YYYY)") E3 = Entry(root, bd =5) def getDate(): print E1.get() print E2.get() print E3.get() submit = Button(root, text ="Submit", command = getDate) label1.pack() E1.pack() label2.pack() E2.pack() label3.pack() E3.pack() submit.pack(side =BOTTOM) root.mainloop() 

when you click the send button, it prints the day and year of the month, and I'm sure you can understand it from there

EDIT

here is an example of a text box to display a diary entry:

 from Tkinter import * root = Tk() text = Text(root) text.insert(INSERT, diary) text.pack() root.mainloop() 

in this example, diary is the diary entry line!

Good luck :)

+10
source

Not enough representatives to comment; but to close the box you would add

 root.destroy() 

Under the getDate () function

0
source

Source: https://habr.com/ru/post/1489579/


All Articles