def create_right(self): self.right_container.update_idletasks() width = self.right_container.winfo_width() height = self.right_container.winfo_height() self.up_button = CustomButton(self.right_container, text="+", command=self.raise_bet, bg="#303030", fg="#ffffff", height=int(height / 2), width=int(width / 4)) self.up_button.grid(column=0, row=0, sticky="nsew") self.down_button = CustomButton(self.right_container, text="-", command=self.lower_bet, bg="#303030", fg="#ffffff", height=int(height / 2), width=int(width / 4)) self.down_button.grid(column=2, row=0, sticky="nsew") self.value_label = CustomLabel( self.right_container, text=self.app.game_controller.current_bet_value, bg="#202020", fg="#ffffff", width=int(width / 4)) self.value_label.grid(column=1, row=0, sticky="nsew")
def create_numbers(self): with open(Path("./Config/roulette_numbers.json"), "r") as read_file: pieces = json.load(read_file) for i in range(10): Grid.rowconfigure(self.frame, i, weight=1) for i in range(15): Grid.columnconfigure(self.frame, i, weight=1) for i, piece in enumerate(pieces["pieces"]): self.frame.update_idletasks() width = self.frame.winfo_width() height = self.frame.winfo_height() but = CustomButton( master=self.frame, fg="white", text=str(i + 1), command=lambda piece=piece: self.make_bet(piece), bg=piece['color'], borderwidth=0, highlightthickness=2, highlightcolor=COLORS['golden']) but.grid(column=(1 + (i // 3)), row=1 + (i % 3), sticky=NSEW) self.buttons.append(but)
def create_roulette(self): self.roulette_view = Roulette(master=self.master, main=self.left_main, app=self) self.display = ResultDisplay(master=self.master, main=self.left_main, app=self) self.spin_button = CustomButton( master=self.left_main, command=lambda: self.game_controller.spin_roulette(), text="SPIN") self.spin_button.grid(column=0, row=2)
def create_zero_button(self): self.frame.update_idletasks() width = self.frame.winfo_width() height = self.frame.winfo_height() but = CustomButton(master=self.frame, fg="white", text="0", command=lambda piece="zero": self.make_bet(piece), bg="#303030") but.grid(rowspan=3, column=0, row=1, sticky=NSEW) self.buttons.append(but)
class Application(Frame): def __init__(self, master=None, roulette=None, game_controller=None): super().__init__(master=master) self.master = master self.game_controller = game_controller self.roulette_controller = roulette self.create_main() def create_main(self): self.create_backbone() self.create_roulette() self.create_table() def create_backbone(self): width = int(self.master.winfo_screenwidth()) height = int(self.master.winfo_screenheight()) self.left_main: Frame = Frame(self.master, bg="#303030", width=int(width / 3), height=height) self.right_main: Frame = Frame(self.master, bg="#303030", width=int(width / 3) * 2, height=height) self.left_main.grid(row=0, column=0) self.left_main.grid_propagate(0) self.right_main.grid(row=0, column=1) self.right_main.grid_propagate(0) def create_roulette(self): self.roulette_view = Roulette(master=self.master, main=self.left_main, app=self) self.display = ResultDisplay(master=self.master, main=self.left_main, app=self) self.spin_button = CustomButton( master=self.left_main, command=lambda: self.game_controller.spin_roulette(), text="SPIN") self.spin_button.grid(column=0, row=2) def create_table(self): self.table_view = Table(master=self.master, main=self.right_main, app=self) self.player_view = PlayerBar(master=self.master, main=self.right_main, app=self) self.player_ui = PlayerUI(master=self.master, main=self.right_main, app=self)
class PlayerUI(): def __init__(self, master, main, app): self.app = app self.master = master self.main = main self.frame = None self.create_ui() def create_ui(self): width = self.main.winfo_width() height = self.main.winfo_height() self.frame = Frame(self.main, width=width, height=height / 6, bg="#303030") self.frame.grid(column=0, row=1) self.frame.grid_propagate(0) self.right_container = Frame(self.frame, width=width / 2, height=height / 6, bg="#303030") self.right_container.grid(column=1, row=0) self.right_container.grid_propagate(0) self.left_container = Frame(self.frame, width=width / 2, height=height / 6, bg="#303030") self.left_container.grid(column=0, row=0) self.left_container.grid_propagate(0) self.create_left() self.create_right() def create_left(self): self.left_container.update_idletasks() width = self.left_container.winfo_width() height = self.left_container.winfo_height() self.name_label = CustomLabel( self.left_container, padx=20, pady=20, fg="white", bg="#303030", text= f"Name: {self.app.game_controller.players[self.app.game_controller.current_player].name}" ) self.name_label.grid(column=0, row=0, sticky="nsew") self.stakes_label = CustomLabel( self.left_container, padx=20, pady=20, fg="white", bg="#303030", text= f"Stakes: {self.app.game_controller.players[self.app.game_controller.current_player].stakes}" ) self.stakes_label.grid(column=0, row=1, sticky="nsew") def update_left(self): self.stakes_label.config( text= f"Stakes: {self.app.game_controller.players[self.app.game_controller.current_player].stakes}" ) self.name_label.config( text= f"Name: {self.app.game_controller.players[self.app.game_controller.current_player].name}" ) def create_right(self): self.right_container.update_idletasks() width = self.right_container.winfo_width() height = self.right_container.winfo_height() self.up_button = CustomButton(self.right_container, text="+", command=self.raise_bet, bg="#303030", fg="#ffffff", height=int(height / 2), width=int(width / 4)) self.up_button.grid(column=0, row=0, sticky="nsew") self.down_button = CustomButton(self.right_container, text="-", command=self.lower_bet, bg="#303030", fg="#ffffff", height=int(height / 2), width=int(width / 4)) self.down_button.grid(column=2, row=0, sticky="nsew") self.value_label = CustomLabel( self.right_container, text=self.app.game_controller.current_bet_value, bg="#202020", fg="#ffffff", width=int(width / 4)) self.value_label.grid(column=1, row=0, sticky="nsew") def update_right(self): self.value_label.config( text=self.app.game_controller.current_bet_value) def raise_bet(self): if self.app.game_controller.players[ self.app.game_controller. current_player].stakes > self.app.game_controller.current_bet_value: self.app.game_controller.current_bet_value += 1 self.update_right() def lower_bet(self): if self.app.game_controller.current_bet_value > 0: self.app.game_controller.current_bet_value -= 1 self.update_right()
def create_extras(self): self.frame.update_idletasks() width = self.frame.winfo_width() height = self.frame.winfo_height() odd = CustomButton(master=self.frame, fg="white", text="Odd", bg="#303030", command=lambda oddeven="odd", bet_type="oddeven": self.make_bet(oddeven=oddeven, bet_type=bet_type)) odd.grid(columnspan=4, column=1, row=0, sticky=NSEW) self.buttons.append(odd) even = CustomButton(master=self.frame, fg="white", text="Even", bg="#303030", command=lambda oddeven="even", bet_type="oddeven": self.make_bet(oddeven=oddeven, bet_type=bet_type)) even.grid(columnspan=4, column=1, row=4, sticky=NSEW) self.buttons.append(even) red = CustomButton(master=self.frame, fg="white", text="Red", bg="#303030", command=lambda color="red", bet_type="color": self. make_bet(color=color, bet_type=bet_type)) red.grid(columnspan=4, column=5, row=0, sticky=NSEW) self.buttons.append(red) black = CustomButton(master=self.frame, fg="white", text="Black", bg="#303030", command=lambda color="black", bet_type="color": self.make_bet(color=color, bet_type=bet_type)) black.grid(columnspan=4, column=5, row=4, sticky=NSEW) self.buttons.append(black) low = CustomButton(master=self.frame, fg="white", text="Low", bg="#303030", command=lambda highlow="low", bet_type="highlow": self.make_bet(highlow=highlow, bet_type=bet_type)) low.grid(columnspan=4, column=9, row=4, sticky=NSEW) self.buttons.append(low) high = CustomButton(master=self.frame, fg="white", text="High", bg="#303030", command=lambda highlow="high", bet_type="highlow": self.make_bet(highlow=highlow, bet_type=bet_type)) high.grid(columnspan=4, column=9, row=0, sticky=NSEW) self.buttons.append(high) top_line = CustomButton(master=self.frame, fg="white", text="TL", bg="#303030", command=lambda line="top", bet_type="line": self.make_bet(line=line, bet_type=bet_type)) top_line.grid(column=14, row=1, sticky=NSEW) self.buttons.append(top_line) mid_line = CustomButton(master=self.frame, fg="white", text="ML", bg="#303030", command=lambda line="mid", bet_type="line": self.make_bet(line=line, bet_type=bet_type)) mid_line.grid(column=14, row=2, sticky=NSEW) self.buttons.append(mid_line) bot_line = CustomButton(master=self.frame, fg="white", text="BL", bg="#303030", command=lambda line="bot", bet_type="line": self.make_bet(line=line, bet_type=bet_type)) bot_line.grid(column=14, row=3, sticky=NSEW) self.buttons.append(bot_line)