I am trying to make a program to play the game lucky 7 as a school project. I made the program earlier and trying to make GUI using Tkinter:
import tkinter as tk
from random import randint
from tkinter import messagebox
def rulebox():
a = tk.Tk()
m = '''How to play:-
1)Enter bet
2)Predict the sum on the two dices
3)Roll The Dice'''
tk.Label(a, text=m).grid()
def start(a, b):
global money
if money < b:
m=messagebox.showerror(title="ValueError",message="Insufficient Funds")
else:
x = randint(1, 6)
y = randint(1, 6)
label = tk.Label(master=window, text=x)
label.place(x=125, y=126)
label1 = tk.Label(master=window, text=y)
label1.place(y=126, x=225)
j = x + y
if a == 1:
if j < 7:
tk.Message(window, text="you win").place(y=250, x=350)
money = money + b
else:
tk.Message(window, text='you lose').place(y=250, x=350)
money = money - b
elif a == 2:
if j == 7:
tk.Message(window, text="you win").place(y=250, x=350)
money = money + 2 * b
else:
tk.Message(window, text='you lose').place(y=250, x=350)
money = money - b
else:
if j > 7:
tk.Message(window, text="you win").place(y=250, x=350)
money = money + b
else:
tk.Message(window, text='you lose').place(y=250, x=350)
money = money - b
g.update()
window = tk.Tk(className="Lucky 7")
window.geometry('800x800')
e = tk.Button(window, text="how to play", command=lambda: rulebox())
e.place(relx=0.5, y=10)
radvar = tk.IntVar()
radvar.set(0)
r1 = tk.Radiobutton(window, text='Below 7', value=1, variable=radvar)
r1.place(y=100, x=125)
r2 = tk.Radiobutton(window, text="7", value=2, variable=radvar)
r2.place(y=100, x=350)
r3 = tk.Radiobutton(window, text="Above 7", value=3, variable=radvar)
r3.place(y=100, x=425)
f = tk.Label(window, text='Enter bet')
f.place(relx=0.3, y=150)
w = tk.Entry(window)
w.place(relx=0.5, y=150)
money = 1000
global g
g = tk.Label(window, text="you have %s" % money)
g.place(relx=0.01, rely=0.01)
k = tk.Button(window, text="Roll the die", command=lambda: start(radvar, int(w.get())))
k.place(relx=0.5, rely=0.5)
window.mainloop()
The problem is the numbers are acting funny, output screen shot attached.I choose below 7 and die sum is 10 it says I won.The code checks out I have no clue as to why this is happening so i guess I cant describe the problem.
Aucun commentaire:
Enregistrer un commentaire