from tkinter import * from otree.api import ( Page, WaitPage, models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) class Constants(BaseConstants): name_in_url = 'trust_simple' players_per_group= None num_rounds = 1 endowment = c(20) instructions_template = 'trust_simple/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): offer_1 = models.IntegerField(widget=widgets.RadioSelect, choices=[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) offer_2 = models.IntegerField(widget=widgets.RadioSelect, choices=[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) offer_3 = models.IntegerField(widget=widgets.RadioSelect, choices=[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) offer_4 = models.IntegerField(widget=widgets.RadioSelect, choices=[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) offer_5 = models.IntegerField(widget=widgets.RadioSelect, choices=[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) offer_6 = models.IntegerField(widget=widgets.RadioSelect, choices=[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) offer_7 = models.IntegerField(widget=widgets.RadioSelect, choices=[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) offer_8 = models.IntegerField(widget=widgets.RadioSelect, choices=[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) sent_amount1 = models.CurrencyField( min=c(0), max=Constants.endowment, doc="""Amount sent by P1""", label="How much do you want to send to participant B?", ) sent_amount2 = models.CurrencyField( min=c(0), max=Constants.endowment, doc="""Amount sent by P1""", label="How much do you want to send to participant B?", ) sent_amount3 = models.CurrencyField( min=c(0), max=Constants.endowment, doc="""Amount sent by P1""", label="How much do you want to send to participant B?", ) sent_amount4 = models.CurrencyField( min=c(0), max=Constants.endowment, doc="""Amount sent by P1""", label="How much do you want to send to participant B?", ) # FUNCTIONS def set_winner(group: Group): players = group.get_players() for p in players: set_payoff(p) def set_payoff(player: Player): player.payoff = player.offer_3 # PAGE class Send(Page): form_model = 'player' form_fields = ['offer_1', 'offer_2', 'offer_3', 'offer_4', 'offer_5','offer_6','offer_7','offer_8'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 1 class WaitForP1(WaitPage): after_all_players_arrive = 'set_winner' class Results(Page): pass page_sequence = [Send, WaitForP1, Results]