.py
files containing your work. (If you upload a screenshot or other file format, you won't get credit.)This homework assignment must be submitted in Gradescope by 10am CST on Tuesday, November 30, 2021.
This homework assignment focuses on tkinter and working with dates and times.
Collaboration is prohibited, and you may only access resources (books, online, etc.) listed below.
The course materials and other resources you are allowed to refer to for this homework are:
(Lecture videos are not linked on worksheets, but are also useful to review while working on worksheets. Video links can be found in the course course Blackboard site.)
This homework is correspondingly short.
This homework assignment has 2 problems, numbered 2 and 3. Thus the grading breakdown is:
Points | Item |
---|---|
2 | Autograder |
4 | Problem 2 |
6 | Total |
Ask your instructor or TA a question by email, in office hours, or on discord.
Gradescope will show the results of the automated syntax check of all submitted files as the score for problem 1.
Make a GUI counter application that has a single button labeled "Increment", and a text label next to it. The text label should initially read 0
, and every time the button is pressed, the number on the label should increase by one. A sample of what using the program should look like is shown below.
You can choose whether to do this by subclassing tkinter.Tk
(which is recommended in general) or by building all the widgets in the main program (as in the first lecture demonstration of GUI programming).
tkinter
and tkinter.ttk
'''Creates a tkinter GUI with a button and a counter for how many times the button has been pressed'''
import tkinter
import tkinter.ttk
class IncrementGUI(tkinter.Tk):
'''A class for a tkinter window'''
def __init__(self):
'''Initialize: create a button and a label'''
super().__init__()
self.count = 0
self.title("Counter")
self.increment_button = tkinter.ttk.Button(self, text = "Increment", command = self.on_click)
self.increment_button.grid(row=0,column=0,padx=5,pady=5,ipadx=10,ipady=10)
self.counter = tkinter.ttk.Label(self, text = self.count)
self.counter.grid(row=0,column=1,padx=5,pady=5,ipadx=10,ipady=10)
def on_click(self):
'''Runs when button is pressed. Increases number on label'''
self.count = self.count + 1
self.counter.config(text=self.count)
window = IncrementGUI()
window.mainloop()
You've just completed the last homework assignment of MCS 260.
(All that remains is Project 4!)