Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32
- Type "copyright", "credits" or "license()" for more information.
- >>> import random
- >>> from tkinter import *
- >>> def main():
- class myGame:
- def __init__(self, parent):
- self.myParent = parent
- self.myLabel = Label(root)
- self.myLabel.configure(text = "Randy", bg ="white")
- self.mylabel.place(x=50,y=0)
- d
- self.compLabel = Label(root)
- self.compLabel.configure(text = "computer", bg = "white", fg = "red")
- self.compLabel.place(x=350,y=0)
- d
- self.playerLabel = Label(root)
- self.playerLabe1.configure(bg="white", height = "2", width = "15", font =24)
- self.resultLabel = Label(root)
- self.resultLabel.configure(bg = "white", height = "3", width = "25", font = 24)
- d
- self.button1 = Button(root, command=self.rock_and_comp)
- self.button1.configure(text = "Rock", bg = "white", borderwidth = "4")
- self.button1.place(x=0,y=100)
- d
- self.button2 = Button(root, command =self.paper_and_comp)
- self.button2.configure(text = "paper", bg = "White", borderwidth = "4")
- self.button2.place(x=50,y = 100)
- s
- self.button3 = button(root, command = self.scissors_and_comp)
- self.button3.configure(text = " Scissors", bg= "white" , borderwidth= "4")
- self.button3.place(x=50,y=100)
- d
- self.compButton1 = Button(root)
- self.compButton1.configure("rock", relief = "groove", borderwidth = "4", state = "disabled")
- self.compButton1.place(x=300, y=100)
- d
- self.compButton2 = Button(root)
- self.compButton2 = configure(text = "scissors", relief = "groove", borderwidth = "4", state = "disabled")
- self.compButton3.place(x=405,y=100)
- d
- def computerRandom(self):
- options = ["Rock", "Paper", "Scissors"]
- computer1 = random.choice(options)
- self.computer.set(options[random])
- return options[randomChoice]
- def game(self, selfComputer):
- if self.playerLabel==self.complabel:
- self.resultLabel["text"] == "Draw!"
- elif self.playerLabel == "Rock" and self.complabel == "paper":
- return "Computer wins!"
- elif self.playerLabel == "paper" and selfComputer == "Scissor":
- return "Computer Wins !"
- elif self.playerLabel == "scissors" and selfComputer == "Rock":
- return "Computer Wins !"
- elif self.playerLabel == "paper" and selfComputer == "Rock":
- return "player Wins !"
- elif self.playerLabel == "rock" and selfComputer == "scissors":
- return "player Wins !"
- elif self.playerLabel == "scissors" and selfComputer == "paper":
- return "Player wins !"
- else:
- return "Player wins!"
- def end(self):
- selfComputer = self.computerRandom()
- result = self.game(selfcomputer)
- if result == "Draw":
- result.Label["text"] = "Draw!"
- elif result == "Computer wins!":
- result.Label["text"] == "You lose!"
- else:
- result.Label = "You Win !"
- rook = Tk()
- root.geometry("500x500+300+300")
- roo.title("Rock, paper, scissors")
- myapp = myGame(root)
- root.mainloop()
- >>> main()
- Traceback (most recent call last):
- File "<pyshell#4>", line 1, in <module>
- main()
- File "<pyshell#3>", line 70, in main
- root.geometry("500x500+300+300")
- NameError: name 'root' is not defined
- >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement