Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import tkinter as GUI
- import tkinter as tk
- import tkinter.messagebox
- import random
- from functools import partial
- import time
- import os
- import sys
- def TheGame():
- def play2():
- button1.config(state='disabled', background="cadetblue",fg="red")
- dice1 = random.randint(1,6)
- dice2 = random.randint(1,6)
- global total
- total = dice1 + dice2
- tkinter.Label(rooter, text="you have rolled " + str(dice1)).grid(row=4)
- tkinter.Label(rooter, text="you have rolled " + str(dice2)).grid(row=5)
- global button5
- button5=Button(rooter, text="Roll again",command=play4)
- button5.grid(row=8)
- if total % 2 == 0:
- tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=6)
- total = total + 10
- tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=7)
- else:
- tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=6)
- total = total - 5
- tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=7)
- if dice1 == dice2:
- button1.config(state='normal', background="white",fg="red",text="DOUBLE ROLL AGAIN",command=double1)
- def play3():
- button2.configure(state=DISABLED, background="cadetblue",fg="red")
- dice4 = random.randint(1,6)
- dice5 = random.randint(1,6)
- global total2
- total2 = dice4 + dice5
- tkinter.Label(rooter, text="you have rolled: " + str(dice4)).grid(row=4, column=4)
- tkinter.Label(rooter, text="you have rolled: " + str(dice5)).grid(row=5, column=4)
- global button6
- button6=Button(rooter, text="Roll again",command=play5)
- button6.grid(row=8,column=4)
- if total2 % 2 == 0:
- tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=6,column=4)
- total2 = total2 + 10
- tkinter.Label(rooter, text="Your total score is " + str(total2)).grid(row=7,column=4)
- else:
- tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=6,column=4)
- total2 = total2 - 5
- tkinter.Label(rooter, text="Your total score is " + str(total2)).grid(row=7,column=4)
- if dice4 == dice5:
- button2.config(state='normal', background="white",fg="red",text="DOUBLE ROLL AGAIN",command=doubledice2)
- def play5():
- dice1 = random.randint(1,6)
- dice2 = random.randint(1,6)
- global total2
- global button8
- button8 = Button(rooter, text="Roll again",command=play8)
- button8.grid(row=20,column=4)
- total2 = total2 + dice1 + dice2
- tkinter.Label(rooter, text="you have rolled " + str(dice1)).grid(row=12,column=4)
- tkinter.Label(rooter, text="you have rolled " + str(dice2)).grid(row=13,column=4)
- if total2 % 2 == 0:
- tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=14,column=4)
- total2 = total2 + 10
- tkinter.Label(rooter, text="Your total score is " + str(total2)).grid(row=15,column=4)
- button6.config(state='disabled')
- else:
- tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=14,column=4)
- total2 = total2 - 5
- tkinter.Label(rooter, text="Your total score is " + str(total2)).grid(row=15,column=4)
- button6.config(state='disabled',background="white",fg="grey",text='Done')
- if dice1 == dice2:
- button6.config(state='normal', background="white",fg="red",text="DOUBLE ROLL AGAIN")
- def play4():
- dice1 = random.randint(1,6)
- dice2 = random.randint(1,6)
- global total
- global button7
- button7 = Button(rooter, text="Roll again",command=play7)
- button7.grid(row=20)
- total = total + dice1 + dice2
- tkinter.Label(rooter, text="you have rolled " + str(dice1)).grid(row=12)
- tkinter.Label(rooter, text="you have rolled " + str(dice2)).grid(row=13)
- if total % 2 == 0:
- tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=14)
- total = total + 10
- tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=15)
- button5.config(state='disabled',background='white',fg="grey",text='Done')
- else:
- tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=14)
- total = total - 5
- tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=15)
- button5.config(state='disabled',background='white',fg="grey",text='Done')
- if dice1 == dice2:
- button5.config(state='normal', background="white",fg="red",text="DOUBLE ROLL AGAIN")
- def play7():
- dice1 = random.randint(1,6)
- dice2 = random.randint(1,6)
- global total
- total = total + dice1 + dice2
- tkinter.Label(rooter, text="you have rolled " + str(dice1)).grid(row=21)
- tkinter.Label(rooter, text="you have rolled " + str(dice2)).grid(row=22)
- if total % 2 == 0:
- tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=23)
- total=total+10
- tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=24)
- button7.config(state='disabled',background='white',fg='grey',text='Done')
- else:
- tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=23)
- total = total - 5
- tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=24)
- button7.config(state='disabled',background='white',fg="grey",text='Done')
- if dice1 == dice2:
- button7.config(state='normal',background='whote',fg='red',text='DOUBLE ROLL AGAIN')
- def play8():
- dice1 = random.randint(1,6)
- dice2 = random.randint(1,6)
- global total2
- total2 = total2 + dice1 + dice2
- tkinter.Label(rooter, text="you have rolled " + str(dice1)).grid(row=21,column=4)
- tkinter.Label(rooter, text="you have rolled " + str(dice2)).grid(row=22,column=4)
- if total2 % 2 == 0:
- tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=23,column=4)
- total2 = total2 +10
- tkinter.Label(rooter, text="Your total score is " + str(total2)).grid(row=24,column=4)
- button8.config(state='disabled',background='white',fg='grey',text='Done')
- else:
- tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=23,column=4)
- total2 = total2 - 5
- tkinter.Label(rooter, text="Your total score is " + str(total2)).grid(row=24,column=4)
- button8.config(state='disabled',background='white',fg="grey",text='Done')
- if dice1 == dice2:
- button8.config(state='normal',background='white',fg='red',text='DOUBLE ROLL AGAIN')
- def double1():
- doubledice1 = random.randint(1,6)
- doubledice2 = random.randint(1,6)
- global total
- total = total + doubledice1 + doubledice2
- tkinter.Label(rooter, text="you have rolled " + str(doubledice1)).grid(row=4)
- tkinter.Label(rooter, text="you have rolled " + str(doubledice2)).grid(row=5)
- if total % 2 == 0:
- tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=6)
- total = total + 10
- tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=7)
- button1.config(state='disabled', background="cadetblue",fg="red")
- else:
- tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=6)
- total = total - 5
- tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=7)
- button1.config(state='disabled', background="cadetblue",fg="red")
- #tomorrow = finish remaking all the doubles like the one above... help me please....#
- def double2():
- doubledice3 = random.randint(1,6)
- doubledice4 = random.randint(1,6)
- def double3():
- doubledice5 = random.randint(1,6)
- doubledice6 = random.randint(1,6)
- def double4():
- doubledice7 = random.randint(1,6)
- doubledice8 = random.randint(1,6)
- def double5():
- doubledice9 = random.randint(1,6)
- doubledice10 = random.randint(1,6)
- def double6():
- doubledice11 = random.randint(1,6)
- doubledice12 = random.randint(1,6)
- rooter = Toplevel()
- rooter.geometry("800x500")
- label = Label(rooter)
- label.img = PhotoImage(file="xd.gif")
- label.config(image=label.img)
- label.grid(row=1)
- button1 = Button(rooter, text="Player One's Roll Buttton",command=play2)
- button2 = Button(rooter, text="Player Two's Roll Button",command=partial(play3))
- button2.grid(row=2,column=4)
- tkinter.Label(rooter, text="Player One's Turn")
- button1.grid(row=2,column=0)
- rooter.mainloop()
- def thelogin():
- creds = 'tempfile.temp' # This just sets the variable creds to 'tempfile.temp'
- def Signup(): # This is the signup definition,
- global pwordE # These globals just make the variables global to the entire script, meaning any definition can use them
- global nameE
- global roots
- roots = Tk() # This creates the window, just a blank one.
- roots.title('Signup') # This renames the title of said window to 'signup'
- intruction = Label(roots, text='Please Enter new Credidentials\n') # This puts a label, so just a piece of text saying 'please enter blah'
- intruction.grid(row=0, column=0, sticky=E) # This just puts it in the window, on row 0, col 0. If you want to learn more look up a tkinter tutorial :)
- nameL = Label(roots, text='New Username: ') # This just does the same as above, instead with the text new username.
- pwordL = Label(roots, text='New Password: ') # ^^
- nameL.grid(row=1, column=0, sticky=W) # Same thing as the instruction var just on different rows. :) Tkinter is like that.
- pwordL.grid(row=2, column=0, sticky=W) # ^^
- nameE = Entry(roots) # This now puts a text box waiting for input.
- pwordE = Entry(roots, show='*') # Same as above, yet 'show="*"' What this does is replace the text with *, like a password box :D
- nameE.grid(row=1, column=1) # You know what this does now :D
- pwordE.grid(row=2, column=1) # ^^
- signupButton = Button(roots, text='Signup', command=FSSignup) # This creates the button with the text 'signup', when you click it, the command 'fssignup' will run. which is the def
- signupButton.grid(columnspan=2, sticky=W)
- roots.mainloop() # This just makes the window keep open, we will destroy it soon
- def FSSignup():
- with open(creds, 'w') as f: # Creates a document using the variable we made at the top.
- f.write(nameE.get()) # nameE is the variable we were storing the input to. Tkinter makes us use .get() to get the actual string.
- f.write('\n') # Splits the line so both variables are on different lines.
- f.write(pwordE.get()) # Same as nameE just with pword var
- f.close() # Closes the file
- roots.destroy() # This will destroy the signup window. :)
- Login() # This will move us onto the login definition :D
- def Login():
- global nameEL
- global pwordEL # More globals :D
- global rootA
- rootA = Tk() # This now makes a new window.
- rootA.title('Login') # This makes the window title 'login'
- intruction = Label(rootA, text='Please Login\n') # More labels to tell us what they do
- intruction.grid(sticky=E) # Blahdy Blah
- nameL = Label(rootA, text='Username: ') # More labels
- pwordL = Label(rootA, text='Password: ') # ^
- nameL.grid(row=1, sticky=W)
- pwordL.grid(row=2, sticky=W)
- nameEL = Entry(rootA) # The entry input
- pwordEL = Entry(rootA, show='*')
- nameEL.grid(row=1, column=1)
- pwordEL.grid(row=2, column=1)
- loginB = Button(rootA, text='Login', command=CheckLogin) # This makes the login button, which will go to the CheckLogin def.
- loginB.grid(columnspan=2, sticky=W)
- rmuser = Button(rootA, text='Delete User', fg='red', command=DelUser) # This makes the deluser button. blah go to the deluser def.
- rmuser.grid(columnspan=2, sticky=W)
- rootA.mainloop()
- def CheckLogin():
- with open(creds) as f:
- data = f.readlines() # This takes the entire document we put the info into and puts it into the data variable
- uname = data[0].rstrip() # Data[0], 0 is the first line, 1 is the second and so on.
- pword = data[1].rstrip() # Using .rstrip() will remove the \n (new line) word from before when we input it
- if nameEL.get() == uname and pwordEL.get() == pword: # Checks to see if you entered the correct data.
- time.sleep(3)
- TheGame()
- sys.exit(thelogin)
- else:
- r = Tk()
- r.title('D:')
- r.geometry('150x50')
- rlbl = Label(r, text='\n[!] Invalid Login')
- rlbl.pack()
- r.mainloop()
- def DelUser():
- os.remove(creds) # Removes the file
- rootA.destroy() # Destroys the login window
- Signup() # And goes back to the start!
- if os.path.isfile(creds):
- Login()
- else: # This if else statement checks to see if the file exists. If it does it will go to Login, if not it will go to Signup :)
- Signup()
- thelogin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement