Hello,
I have been following discussions and codes for a while on Daniweb, and I'm really interested in this amazing community. I just joined though.
I'm facing a problem in my Tk inter task.
I have a code and I need to make a TKinter interface that does the job instead of having a normal interface.
I would really appreciate some help regarding this issue and any kind of help/comment/support/advice is appreciated :)
I'm REALLY VERY new to tkinter, as I have learned how to code, but still new to put it in a GUI style.
this is my code ..
## Taiki
## this is a vending machine
## there is two kinds of users, 1. Admin 2. buyer.
## I'm using three classes as I decided to practice classes and inheri.
## Vending Machine 2011
class Coin(object):
def __init__(self,denom,value):
self.Denomination = "CENTS"
self.Value = 0
if value == 25 or value == 50:
self.Value = value
def getValue(self):
return self.Value
def setValue(self,v):
self.Value = 0
if value == 25 or value == 50:
self.Value = value
def getDenomiation(self):
return self.Denomination
def setDenomination(self, d):
self.Denomination = d
def __str__(self):
return str(self.Value)+" " + self.Denomination
class Item(object):
def __init__(self,n,c,p,q):
self.Name = n
self.Code = c
self.Price = p
self.Quantity = q
def getName(self):
return self.Name
def setName(self,n):
self.Name = n
def getCode(self):
return self.Code
def setCode(self,n):
self.Code = n
def getPrice(self):
return self.Price
def setPrice(self,n):
self.Price = n
def getQuantity(self):
return self.Quantity
def setQuantity(self,n):
self.Quantity = n
def __str__(self):
output = "Name: " + self.Name
output += "\nCode: " + self.Code
output += "\nPrice: " + str(self.Price)
output += "\nQuantity: " + str(self.Quantity)
return output
class VendingMachine(object):
def __init__(self):
self.allItems = []
self.amount = 0
def getItems(self):
return self.allItems
def getAmount(self):
return self.amount
def setAmount(self,a):
self.amount = a
def addItem(self, It):
for i in self.allItems:
if i.getCode() == It.getCode():
i.setQuantity(i.getQuantity() + It.getQuantity())
return
self.allItems.append(It)
def insertCoin(self, cn):
if cn.getValue() == 25 or cn.getValue() == 50:
self.amount += cn.getValue()*1.0/100
def vendItem(self,code):
for i in self.allItems:
if i.getCode() == code:
if i.getQuantity() > 0:
if self.getAmount() >= i.getPrice():
self.setAmount(self.getAmount() - i.getPrice())
i.setQuantity(i.getQuantity() - 1)
print "Name: " + i.Name
print "Code: " + str(i.Code)
print "Price: " + str(i.Price)
else:
print "Not Enough Money to Buy " + i.getName()
else:
print "Quantity Out of Stock"
return
print "Item with Code " + str(code)+" does not exist"
def returnBalance(self):
print "Amount Returned = "+str(self.getAmount())
self.setAmount(0)
def printMenu():
print " __________________________"
print "|Menu |"
print "|--------------------------|"
print "| 1. Stock an Item |"
print "| 2. Display all Items |"
print "| 3. Insert 25 cents |"
print "| 4. Insert 50 cents |"
print "| 5. Buy Item |"
print "| 6. Get Change |"
print "| 7. Print Current Amount |"
print "| 8. Exit |"
print "|__________________________|"
def StockItem(Vm):
name = raw_input("Enter Name of Item> ")
price = float(raw_input("Enter Price> "))
code = raw_input("Enter Code> ")
quant = int(raw_input("Enter Quantity> "))
itm = Item(name,code,price,quant)
Vm.addItem(itm)
def DisplayAllItems(Vm):
itms = Vm.getItems()
for i in itms:
print i
def Insert25Cents(Vm):
C25 = Coin("cents",25)
Vm.insertCoin(C25)
def Insert50Cents(Vm):
C50 = Coin("cents",50)
Vm.insertCoin(C50)
def BuyItem(Vm):
code = raw_input("Enter Code of Item you want to buy> ")
Vm.vendItem(code)
def GetChange(Vm):
Vm.returnBalance()
def PrintAmt(Vm):
print "Current Amount is "+str(Vm.getAmount())
inp = 0
Vmach = VendingMachine()
while inp != 8:
printMenu()
inp = int(raw_input("Enter your choice> "))
if inp == 1:
StockItem(Vmach)
elif inp == 2:
DisplayAllItems(Vmach)
elif inp == 3:
Insert25Cents(Vmach)
elif inp == 4:
Insert50Cents(Vmach)
elif inp == 5:
BuyItem(Vmach)
elif inp == 6:
GetChange(Vmach)
elif inp == 7:
PrintAmt(Vmach)
elif inp == 8:
print "Thank you for your business"
The code is working, as I said before, I need to put in an elegant-simple interface too.
Thanks