python - Need help finishing a darts scoring system -


i have created darts scoring system accepts multiple players , displayed on tkinter gui. real darts game each player starts 501 points , have buttons subtract score simulate dart throws.

i'm finished except want players score doesn't go past 0 @ moment score not stop @ 0 goes negative numbers. example if player on 5 points , landed 20 point throw score go -15 instead of 0. appreciated!

here's code (sorry rather long):

import tkinter tkinter import *  class application(object):      def __init__(self):         self.playernames = []         self.playerscores = []         self.root = tkinter.tk()          self.gamecounter=0          self.numberplayers=0         self.inputnumber=0         self.root.title("darts!")         self.root.configure(background="light blue")          self.welcomelabel = tkinter.label(text="welcome darts!", bg="light blue", fg="red")         self.welcomelabel.grid(column=0, row=0)          self.dartslabel = tkinter.label(text = "enter player names in 1 one", bg="light blue", fg="dark blue")         self.dartslabel.grid(column=0, row=1)          self.nameentry = tkinter.entry(text="ok", fg="purple")         self.nameentry.grid(column=0, row=2)          self.btnaddlistitem = tkinter.button(text = "add player", command = self.addnewname, bg="light grey")         self.btnaddlistitem.grid(column=0, row=3)          self.finishedadding = tkinter.button(text = "play darts!", command = self.displaynames, bg="light grey")         self.finishedadding.grid(column=0, row=4)          self.quitbtn = tkinter.button(text="quit", command=self.comfirmquit, bg="light grey")         self.quitbtn.grid(column=0, row=20)      def comfirmquit(self):         self.comfirmquitlabel = tkinter.label(text="are sure?", bg="light blue", fg="red")         self.comfirmquitlabel.grid(column=0, row=21)          self.comfirmquitbutton = tkinter.button(text="yes", command= self.quitgame, bg="light grey")         self.comfirmquitbutton.grid(column=0, row=22)          self.cancelquitbutton = tkinter.button(text="no", command=self.cancelquit, bg="light grey")         self.cancelquitbutton.grid(column=0, row=23)      def quitgame(self):         global root         self.root.destroy()      def cancelquit(self):         self.comfirmquitbutton.destroy()         self.cancelquitbutton.destroy()         self.comfirmquitlabel.destroy()      def addnewname(self):         inputname = self.nameentry.get()         self.playernames.append(inputname)         self.nameentry.delete(0, tkinter.end)      def displaynames(self):         self.welcomelabel.destroy()         self.dartslabel.destroy()         self.nameentry.destroy()         self.btnaddlistitem.destroy()         self.finishedadding.destroy()         self.labelsforplayernames = []         self.numberplayers=len(self.playernames)         while self.numberplayers>self.gamecounter:             self.playerscores.append(501)             self.gamecounter+=1         self.turncounter=0         self.playercounter=0         self.roundnumber=1         self.thescore()      def thescore(self):          self.dartslabel = tkinter.label(text = "turn: " + self.playernames[0], bg="light blue", fg="dark blue")         self.dartslabel.grid(column=0, row=0)         self.playerscorelabel = tkinter.label(text =self.playerscores[0], bg="light blue", fg="red")         self.playerscorelabel.grid(column=0, row=3)         self.scorespin=spinbox(from_ =1, to=20, bg="light grey", fg="purple")         self.scorespin.grid(column=0, row=2)          self.btnaddlistitem = tkinter.button(text = "no multiplier", command = self.singlescore, bg="light grey")         self.btnaddlistitem.grid(column=0, row=4)         self.btnaddlistitem = tkinter.button(text = "2x multiplier", command = self.doublescore, bg="light grey")         self.btnaddlistitem.grid(column=0, row=5)         self.btnaddlistitem = tkinter.button(text = "3x multiplier", command = self.triplescore, bg="light grey")         self.btnaddlistitem.grid(column=0, row=6)         self.btnaddlistitem = tkinter.button(text = "half bullseye", command = self.scorehalfbullseye, bg="light grey")         self.btnaddlistitem.grid(column=0, row=7)         self.btnaddlistitem = tkinter.button(text = "bullseye", command = self.scorebullseye, bg="light grey")         self.btnaddlistitem.grid(column=0, row=8)      def singlescore(self):         self.inputnumber = int(self.scorespin.get())         self.scoringsystem()     def doublescore(self):         self.inputnumber = int(self.scorespin.get())         self.inputnumber=self.inputnumber*2         self.scoringsystem()      def triplescore(self):         self.inputnumber = int(self.scorespin.get())         self.inputnumber=self.inputnumber*3         self.scoringsystem()     def scorehalfbullseye(self):         self.inputnumber = 25         self.scoringsystem()     def scorebullseye(self):         self.inputnumber = 50         self.scoringsystem()      def scoringsystem(self):         self.turncounter+=1         self.playerscores[self.playercounter]=self.playerscores[self.playercounter]-self.inputnumber         self.playerscorelabel.config(text= self.playerscores[self.playercounter])         self.dartslabel.grid(column=0, row=3)          if self.turncounter>2:                             self.playercounter+=1             self.turncounter=0          if self.playercounter>=self.numberplayers:             self.playercounter=0             self.roundnumber+=1             self.displayscores()         self.dartslabel.config(text= "turn: " + self.playernames[self.playercounter])         self.dartslabel.grid(column=0, row=0)         self.root.wm_title("round: %d" % self.roundnumber)      def displayscores(self):         self.dartslabel.destroy()         self.scorespin.destroy()         self.btnaddlistitem.destroy()         self.root.wm_title("round scores")         self.thescore()     myapp = application() myapp.root.mainloop() 

assuming want nothing happen when potential score greater actual score:

if potential_score > actual_score:     pass else:     compute_score() 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -