In: Computer Science
The objective of this project is to practice using Pythons GUI tkinter. You must use tkinter and no other GUI product.
Design a small (ie 2x3) GUI window which contains 4 items:
1. A text keyin field,
2. An Execute button,
3. An Exit Button
4. A label.
When the user clicks on the execute button, the text located in the keyin field will be displayed on the label. If the keyin field contains no text, a message box should display saying, “No Text to Display.”
When the user clicks on the exit button, the program should terminate. Therefore, use the sys.exit() method from the sys package.
from tkinter import*
from tkinter import messagebox
import sys
root=Tk()
#Function to display the label
def selection():
a=e1.get()
if(len(a)==0):
output = "No Text to Display"
messagebox.showinfo("results",output)
else:
w=Label(root,text=a)
w.grid(row=0, column=1)
#function to exit
def end():
sys.exit()
e1=Entry(root)
e1.grid(row=0)
b1=Button(root,text='Submit',fg="Black",command = selection)
b1.grid(row=1)
b1=Button(root,text=' Exit ',fg="Black",bg="red", command =
end)
b1.grid(row=1, column=1)
root.mainloop()