Hello, it is me again with another homework assignment. I am having issues starting this one. Every draft I make for it feels way too long and that I can make it much, much shorter.
First, I am using Python version 2.3.2. I am using graphics.py, buttons.py, and am basing charview.py on dieview.py from Zelle's website. I am running on Window's Vista. I am also suppose to base my program on roller.py from Zelle's website, but I am having difficulty understanding everything regarding the interactions between my program, charview.py, and buttons.py.
The assignment:
This program creates a 4-digit counter with up and down buttons for each digit. The following is required:
-1) The clear button is only active when a non-zero value is displayed
-2) The value must always be between 0 and 9990. Decreasing by an amount greater than display will result in 0000.
-3) The display must show "- - - -" before any clicks.
-4) Must use the Button class from Zelle unchanged
-5) Must create a module named charview (charview.py) containing the class CharView.
-6) Must create counter.py that contains main() and any other support functions.
-7) Window must be 400x300 and arrange the up and down buttons beneath the appropriate digit, with up on top and down below. The clear button should be centered and quit button should be beneath it.
I know charview.py is not complete, but I am drawing nothing but blanks as to where I should start next. Here is what I currently have for charview.py:
#A widget for displaying the digits of the number counter
from graphics import *
class charView:
""" charView is a widget that displays a graphical representation of a number counter."""
def __init__(self, win, center, size):
"""Create a view of a digit"""
# first define some standard values
self.win = win # save this for drawing pips later
self.background = "white" # color of the background
self.foreground = "black" # color of the numbers
hsize = size / 2.0 # half the size of the die
# create a square for the face
cx, cy = center.getX(), center.getY()
p1 = Point(cx-hsize, cy-hsize)
p2 = Point(cx+hsize, cy+hsize)
rect = Rectangle(p1,p2)
rect.draw(win)
rect.setFill(self.background)
# Draw an initial value
self.setValue(1)
def setValue(self, value):
""" Set this digit to display value."""
# turn all digits off
# turn correct digit value on
if value == 1:
elif value == 2:
elif value == 3:
elif value == 4:
elif value == 5:
elif value == 6:
elif value == 7:
elif value == 8:
elif value == 9:
else:
I am fairly certain that it will be easy to increase and decrease the value. The hard part is displaying the value when an increase or decrease occurs. As such, here is the code I currently have to counter.py:
from graphics import GraphWin, Point
from button import button
from charView import charView
def main():
#create the application window
win = GraphWin("Up-Down Counter")
win.setCoords(0,0,400,300)
win.setBackground("cyan")
#Draw the interface widgets
thousands = charView(win, Point(49.75,250), 20)
hundreds = charView(win, Point(149.25,250), 20)
tens = charView(win, Point(248.75,250), 20)
ones = charView(win, Point(348.25,250), 20)
#create the buttons to increase and decrease each digit
#Spaced by ones, tens, hundreds, and thousands to make reading easier
oIB = Button(win, Point(348.25,200), 6, 1, "+1") # oIB stands for onesIncreaseButton
oIB.activate()
oDB = Button(win, Point(348.25,150), 6, 1, "-1") #oDB stands for onesDecreaseButton
oDB.activate()
tIB = Button(win, Point(248.75,200), 6, 1, "+10") #tIB stands for tensIncreaseButton
tIB.activate()
tDB = Button(win, Point(248.75,150), 6, 1, "-10") #tDB stands for tensDecreaseButton
tDB.activate()
hIB = Button(win, Point(149.75,200), 6, 1, "+100") #hIB stands for hundredsIncreaseButton
hIB.activate()
hDB = Button(win, Point(149.75,150), 6, 1, "-100") #hDB stands for hundredsDecreaseButton
hDB.activate()
kIB = Button(win, Point(49.75,200), 6, 1, "+1000") #kIB stands for thousandsIncreaseButton
kIB.activate()
kDB = Button(win, Point(49.75,150), 6, 1, "-1000") #kDB stands for thousandsDecreaseButton
kDB.activate()
#create the clear and quit buttons
clearButton = Button(win, Point(200,100), 2, 1, "Clear")
quitButton = Button(win, Point(200,50), 2, 1, "Quit")
while not quitButton.clicked(pt):
pt = win.getMouse()
That is as far as I have been able to get on my own. This has been assigned for about a week, and I have about a week left to complete it. I would prefer suggestions over someone else solving this assignment for me. Thank you to anyone who offers suggestions.