Question

In: Computer Science

For this assignment, you will develop working examples of a graphical user interface (GUI) and event...

For this assignment, you will develop working examples of a graphical user interface (GUI) and event handling and that demonstrate the following:


Working code with screenshots of a Python GUI application that includes 5 design widgets of your choosing


Working code with screenshots of event handling in Python based on 3 events of your choosing


Be sure to include a brief narrative of your code where you explain what the code is doing.

Documentation Guidelines:

Use good programming style (e.g., indentation for readability) and document each of your program parts with the following items (the items shown between the '<' and '>' angle brackets are only placeholders.  You should replace the placeholders and the comments between them with your specific information).  Your cover sheet should have some of the same information, but what follows should be at the top of each program's sheet of source code.  Some lines of code should have an explanation of what is to be accomplished, this will allow someone supporting your code years later to comprehend your purpose.  Be brief and to the point.  Start your design by writing comment lines of pseudocode.  Once that is complete, begin adding executable lines.  Finally run and test your program.

written in python code.

Solutions

Expert Solution

The source code is given below:

"""
File: gui.py
Used widgets: Label,Button,Radiobutton,Entry,ScrolledText
Used events: click on buttons,radio button selection, Keyevent on entry widget
"""

# import of tkinter library
import tkinter as tk
import tkinter.scrolledtext as st
# global variable
s=0
# keyevent is fired when ENTER key is pressed after typing in entry widget
def keyEvent(event):
showText()
# to display the item selected and its price within ScrolledText
def showText():
# using global variable
global s
# gets value from entry widget
s1=e1.get()
# checks if something is typed inside entry widget
if(s1!=''):
# if typed then converts to int and calculates total
s=s+int(s1)
# inserts into ScrolledText
txt.insert('insert',"You choose:"+v.get()+" "+e1.get()+"\n")
# clears the entry widget
e1.delete(0,'end')
# to display total inside ScrolledText
def showTotal():
global s
txt.insert('insert',"--------------------------------\n");
txt.insert('insert',"Total spent:"+str(s)+"\n")
# root window from tkinter
root=tk.Tk()
# v declared as command variable to store a string while being used with Radiobutton
# the value of Radiobutton will be available in variable v
v=tk.StringVar()
# radiobutton with value "Cheese" selected initially
v.set("Cheese")
# initialization of Radiobutton 1
rb1=tk.Radiobutton(root,text="Milk",padx = 20,variable=v,value="Milk")
# Radiobutton 1 placed in grid(0,0)
rb1.grid(row=0,column=0)
# initialization of Radiobutton 2
rb2=tk.Radiobutton(root,text="Cheese",padx = 20,variable=v,value="Cheese")
# Radiobutton 2 placed in grid(0,1)
rb2.grid(row=0,column=1)
# initialization of Radiobutton 3
rb3=tk.Radiobutton(root,text="Fruits",padx = 20,variable=v,value="Fruits")
# Radiobutton 3 placed in grid(0,3)
rb3.grid(row=0,column=2)
# initialization of label showing text and placed in grid(1,0)
tk.Label(root,text="Amount Spent").grid(row=1,column=0)
# initialization of entry widget to accept number entry
e1=tk.Entry(root)
# placed in grid(1,1)
e1.grid(row=1,column=1)
# keyEvent bound to entry e1 so that on pressing ENTER key on it will be fired
e1.bind("<Return>",keyEvent)
#initialization of Button1 widget
b1=tk.Button(root,text="ADD MONEY SPENT",command=showText,width=40)
# placed in grid(1,2)
b1.grid(row=1,column=2)
#initialization of Button2 widget
b2=tk.Button(root,text="TOTAL MONEY SPENT",command=showTotal,width=40)
# placed in grid(2,2)
b2.grid(row=2,column=2)
#initialization of ScrolledText
txt=st.ScrolledText(root,height=6)
# placed in grid(3,0) with spanning over 3 columns
txt.grid(row=3,column=0,columnspan=3)
# window size of 600x200 with initial position at (300,300)
root.geometry("600x200+300+300")
#window mainloop
root.mainloop()

##########################

The source code screen shot is given below for indentation reference:

The output screen shot is given below:


Related Solutions

Using matlab: Build a graphical user interface (GUI) the will read the two corners of a...
Using matlab: Build a graphical user interface (GUI) the will read the two corners of a rectangle (from the GUI interface) and show the following: A plot of the rectangle (you should have display for it) Show the centroid (the center of the rectangle) on the graph. Calculate the area and the circumference of the triangle (you need to write a function for that). The interface should have at least the following: Four textboxes to read the ( 2 for...
Develop a JavaFX GUI application called Registration that implements a user interface for registering for a...
Develop a JavaFX GUI application called Registration that implements a user interface for registering for a web site. The application should have labeled text fields for the Full Name, User Name, Password, Student Id, and a TextAreafor About Me. Include a button labeled Send. When the Send button is clicked, your program should print the contents of all fields (with labels) to standard output using println()statements.
*In JAVA and JavaFX please!! CSE1322 – Assignment 8 – GUI General User Interface Assignment 8...
*In JAVA and JavaFX please!! CSE1322 – Assignment 8 – GUI General User Interface Assignment 8 Objectives • Build a GUI application similar to a calculator. • Create an application that acts as a simple calculator. Create buttons for 0-9 and a text field that displays the concatenation of the current digits as they are clicked. • Add buttons for operators “+”, “-“, “*”, and “/”. • Add a final button for “=” that calculates the computed value with the...
Develop a GUI to get unique names from the user.
in JAVADevelop a GUI to get unique names from the user. . In the first frame use a label ("Name") a textfield and 2 buttons (ext' and 'inished") . In the second frame there should be a list and a scrollpane as the components . Use the components on the first frame to get the name value from the user. . When the user enters a name make sure it is not empty and has no spaces and dicks the next' button, reset the...
The purpose of this problem is to use graphic user interface (GUI) to interactively store grades...
The purpose of this problem is to use graphic user interface (GUI) to interactively store grades in a text file, rather than adding them manually to a script. Follow these steps to complete the program: Step 1. Use a question dialog box and ask the user “Do you want to run this Program?” with two options for “yes” and “no”. If the user’s answer is “yes”, go to the next step, otherwise, go to Step 6. Step 2. Create a...
Use the below info to create a java program A GUI interface to ensure a user...
Use the below info to create a java program A GUI interface to ensure a user is old enough to play a game. Properly formatted prompts to input name, address, phone number, and age. Remember that name, address, phone number, etc. can be broken out in additional fields. Refer to the tutorial from this week’s Reading Assignment Multiple vs. Single Field Capture for Phone Number Form Input for help with this. Instructions to ensure that the information is displayed back...
The operating system offers a graphical vs command line user interface to interact with an electronic...
The operating system offers a graphical vs command line user interface to interact with an electronic device. Compare the graphical user interface and the command line interface in terms of speed, remote access, resource utilization, multitasking, and control.
The operating system offers a graphical vs command line user interface to interact with an electronic...
The operating system offers a graphical vs command line user interface to interact with an electronic device. Compare the graphical user interface and the command line interface in terms of speed, remote access, resource utilization, multitasking, and control. [5 Marks]
You and your team are now working on some icons for the organization’s program user interface...
You and your team are now working on some icons for the organization’s program user interface (UI). Based on your first mock-up of the UI, complete the following: Discuss 2 original icons with 3 states each. Explain how the icons would be used, and give the purpose of each state. Investigate emerging alternative I/O devices and discuss their impacts on design.
Develop a job description and person specification for a volunteer working at an event information kiosk.
Develop a job description and person specification for a volunteer working at an event information kiosk.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT