Name rolling game using python with GUI.

             Welcome to name rolling game


This is name rolling game using python with GUI.

You just only need to need module and paste then run.


import these module      tkinter , matplotlib , numpy , random 




#
# copyright by pyprojectlab
#
import tkinter as tk
from tkinter import simpledialog, messagebox
import matplotlib.pyplot as plt
import numpy as np
import random
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg


class NameRollingGame(tk.Tk):
def __init__(self):
super().__init__()
self.title("Name Rolling Game")
self.geometry("800x600")

self.names = []

self.add_name_button = tk.Button(self, text="Add Name", command=self.add_name)
self.add_name_button.pack(side=tk.LEFT, padx=20)

self.spin_button = tk.Button(self, text="Spin", command=self.spin_wheel)
self.spin_button.pack(side=tk.RIGHT, padx=20)

self.fig, self.ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(aspect="equal"))
self.canvas = FigureCanvasTkAgg(self.fig, master=self)
self.canvas.get_tk_widget().pack(fill=tk.BOTH, expand=True)
self.update_wheel()

def add_name(self):
name = simpledialog.askstring("Input", "Enter a name:")
if name:
self.names.append(name)
self.update_wheel()

def update_wheel(self):
self.ax.clear()
if self.names:
wedges, texts = self.ax.pie([1] * len(self.names), labels=self.names, colors=plt.cm.tab20.colors)
else:
wedges, texts = self.ax.pie([1], labels=["No names"], colors=["gray"])
self.canvas.draw()

def spin_wheel(self):
if not self.names:
messagebox.showinfo("Info", "Add at least one name before spinning.")
return

# Simulate spinning
for _ in range(random.randint(10, 30)):
random.shuffle(self.names)
self.update_wheel()
self.update()
self.after(100)

winner = random.choice(self.names)
messagebox.showinfo("Winner", f"The winner is {winner}!")
self.update_wheel()


if __name__ == "__main__":
app = NameRollingGame()
app.mainloop()

Comments

Popular posts from this blog

Screen Recording using python.

wallpaper changer.

Find any color from image using python