Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter.font import Font
- from PIL import Image, ImageTk
- import random
- import os
- cardSize = [350, 500] # the card size
- root = tk.Tk() # Creates the window
- root.title("Game Master Apprentace") #Changes the window title
- canvas = tk.Canvas(root, height=1000, width=1900, bg='SlateBlue1') #creates a canvas and default window size for you to write on
- canvas.pack() #packs canvas, puts it into the loop and places it on the board
- frame = tk.Frame(root, bg='SlateBlue1') #makes a new frame for us to put things in, changes background color to pink
- frame.place(relx=0.25, rely=0.10, relheight=0.75, relwidth=0.75) #places the frame in the middle of the screen, filling 75% of the screen vertically, and 50% of the screen horizontally
- frame_left = tk.Frame(frame, bg='SlateBlue1')
- frame_left.place(relx=0, rely=0, relheight=1, relwidth=0.34)
- frame_middle = tk.Frame(frame, bg='SlateBlue1')
- frame_middle.place(relx=0.33, rely=0, relheight=1, relwidth=0.34)
- frame_right = tk.Frame(frame, bg='SlateBlue1')
- frame_right.place(relx=0.66, rely=0, relheight=1, relwidth=0.34)
- menu = tk.Frame(root, bg='SlateBlue1')
- menu.place(relx=0, rely=0, relheight=1, relwidth=0.20)
- print("we are rebuilding")
- def randomCards():
- os.chdir(r"p:\Projects\Python\This is the GM folder\images") #changes the directory commands are sent from
- file_choice2 = random.choice(os.listdir()) # randomly chooses a file from the directory given
- file_open2 = Image.open(file_choice2) # opens the file
- resized_file2 = file_open2.resize((cardSize[0], cardSize[1]), Image.ANTIALIAS) #resizes file
- file2 = ImageTk.PhotoImage(resized_file2) # loads the file and assigns it to a var
- my_lable2 = tk.Label(frame_left, image=file2, bg='SlateBlue1') # makes a place for us to put the image, and assigns the image value to
- my_lable2.place(relx=0, rely=0.1, relheight=1, relwidth=1) # says that the picture will be place starting from the top left of the area, and be the full length and width of the
- file_choice3 = random.choice(os.listdir()) # randomly chooses a file from the directory given
- file_open3 = Image.open(file_choice3) # opens the file
- resized_file3 = file_open3.resize((cardSize[0], cardSize[1]), Image.ANTIALIAS) #resizes file
- file3 = ImageTk.PhotoImage(resized_file3) # loads the file and assigns it to a var
- my_lable3 = tk.Label(frame_middle, image=file3, bg='SlateBlue1') # makes a place for us to put the image, and assigns the image value to
- my_lable3.place(relx=0, rely=0.1, relheight=1, relwidth=1) # says that the picture will be place starting from the top left of the area, and be the full length and width of the
- file_choice4 = random.choice(os.listdir()) # randomly chooses a file from the directory given
- file_open4 = Image.open(file_choice4) # opens the file
- resized_file4 = file_open4.resize((cardSize[0], cardSize[1]), Image.ANTIALIAS) #resizes file
- file4 = ImageTk.PhotoImage(resized_file4) # loads the file and assigns it to a var
- my_lable4 = tk.Label(frame_right, image=file4, bg='SlateBlue1') # makes a place for us to put the image, and assigns the image value to
- my_lable4.place(relx=0, rely=0.1, relheight=1, relwidth=1) # says that the picture will be place starting from the top left of the area, and be the full length and width of the3
- print("you clicked the button")
- twenty = random.randint(0,20)
- onehundred = random.randint(0,100)
- six = random.randint(0,6)
- # Text for all cards.
- left_lable = tk.Label(frame_left, text="Main Card", bg="Green", fg="white",font=('Helvetica bold', 26))
- center_lable = tk.Label(frame_middle, text="Seccond Card.", bg="Green", fg="white",font=('Helvetica bold', 26))
- right_label = tk.Label(frame_right, text="Third card.", bg="Green", fg="white",font=('Helvetica bold', 26))
- roll_twenty = tk.Label(menu, text=twenty, bg="Green", fg="white",font=('Helvetica bold', 26))
- roll_onehundred = tk.Label(menu, text=onehundred, bg="Green", fg="white",font=('Helvetica bold', 26))
- roll_six = tk.Label(menu, text=six, bg="Green", fg="white",font=('Helvetica bold', 26))
- roll_twenty.place(relx=0.05, rely=0.30)
- roll_onehundred.place(relx=0.05, rely=0.40)
- roll_six.place(relx=0.05, rely=0.50)
- left_lable.place(relx=0.3, rely=0.10)
- center_lable.place(relx=0.21, rely=0.10)
- right_label.place(relx=0.25, rely=0.10)
- root.mainloop()
- print("remaking the box")
- new_card_button = tk.Button(menu, bg='lightblue', text='redraw card',font=('Helvetica bold', 15), command=randomCards)
- new_card_button.place(relx=0.05, rely=0.05, relwidth=0.40, relheight=0.07)
- root.mainloop() # Where the loop happens, all things happening to the window must be above
Add Comment
Please, Sign In to add comment