Python Gui Program

Submitted by: Submitted by

Views: 48

Words: 452

Pages: 2

Category: Other Topics

Date Submitted: 11/20/2014 01:28 PM

Report This Essay

from Tkinter import *

from ttk import *

import random

import sys

##def makeYourChoice():

## print "Press R for Rock"

## print "Press P for Paper"

## print "Press S for Scissors"

## print "Press Q to quit!"

##

## userChoice = raw_input("What do you want to choose?").lower()

##

## ### Using if rather then elif

## if userChoice == "r":

## return "Rock"

## if userChoice == "p":

## return "Paper"

## if userChoice == "s":

## return "Scissors"

## if userChoice == "q":

## sys.exit(0)

##

## else:

## makeYourChoice()

def computerRandom():

options = ["Rock","Paper","Scissors"]

randomChoice = random.randint(0,2)

computer_choice.set(options[randomChoice]) ##added into the program

return options[randomChoice]

def comparison(humanChoice, computerChoice):

if humanChoice == computerChoice:

return "Draw"

if humanChoice == "Rock" and computerChoice == "Paper":

return "Computer Wins"

if humanChoice == "Paper" and computerChoice == "Scissors":

return "Computer Wins"

if humanChoice == "Scissors" and computerChoice == "Rock":

return "Computer Wins"

else: return "Human Wins"

def play():

humanChoice = player_choice.get() ##Modified this line

computerChoice = computerRandom()

#print player_choice.get() ## This line is no longer needed

#print computer_choice.get() ## This line is no longer needed

## if player_choice.get() != '':

## Indent lines below if line above is uncommented.

result = comparison(humanChoice, computerChoice)

if result == "Draw":

result_set.set("Its a draw")

elif result == "Computer Wins":

result_set.set("Unlucky you lost!")

else: result_set.set("Well done you won!")

## else:

## result_set.set("Please choose an option")

##while True:

##...