Maderdash

the first draft

Sep 10th, 2021 (edited)
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.30 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter.font import Font
  3. from PIL import Image, ImageTk
  4. import random
  5. import os
  6.  
  7. cardSize = [350, 500]                                            # the card size
  8.  
  9.  
  10. root = tk.Tk()                                                   # Creates the window
  11. root.title("Game Master Apprentace")                             #Changes the window title
  12. canvas = tk.Canvas(root, height=1000, width=1900, bg='SlateBlue1')                #creates a canvas and default window size for you to write on
  13. canvas.pack()                                                    #packs canvas, puts it into the loop and places it on the board
  14.  
  15. frame = tk.Frame(root, bg='SlateBlue1')                                #makes a new frame for us to put things in, changes background color to pink
  16. 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
  17. frame_left = tk.Frame(frame, bg='SlateBlue1')
  18. frame_left.place(relx=0, rely=0, relheight=1, relwidth=0.34)
  19. frame_middle = tk.Frame(frame, bg='SlateBlue1')
  20. frame_middle.place(relx=0.33, rely=0, relheight=1, relwidth=0.34)
  21. frame_right = tk.Frame(frame, bg='SlateBlue1')
  22. frame_right.place(relx=0.66, rely=0, relheight=1, relwidth=0.34)
  23. menu = tk.Frame(root, bg='SlateBlue1')
  24. menu.place(relx=0, rely=0, relheight=1, relwidth=0.20)
  25. print("we are rebuilding")
  26.  
  27. def randomCards():
  28.    
  29.     os.chdir(r"p:\Projects\Python\This is the GM folder\images") #changes the directory commands are sent from
  30.     file_choice2 = random.choice(os.listdir())                   # randomly chooses a file from the directory given
  31.     file_open2 = Image.open(file_choice2)                        # opens the file
  32.     resized_file2 = file_open2.resize((cardSize[0], cardSize[1]), Image.ANTIALIAS) #resizes file
  33.     file2 = ImageTk.PhotoImage(resized_file2)                    # loads the file and assigns it to a var
  34.     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
  35.     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
  36.  
  37.  
  38.     file_choice3 = random.choice(os.listdir())                   # randomly chooses a file from the directory given
  39.     file_open3 = Image.open(file_choice3)                        # opens the file
  40.     resized_file3 = file_open3.resize((cardSize[0], cardSize[1]), Image.ANTIALIAS) #resizes file
  41.     file3 = ImageTk.PhotoImage(resized_file3)                    # loads the file and assigns it to a var
  42.     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
  43.     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
  44.    
  45.     file_choice4 = random.choice(os.listdir())                   # randomly chooses a file from the directory given
  46.     file_open4 = Image.open(file_choice4)                        # opens the file
  47.     resized_file4 = file_open4.resize((cardSize[0], cardSize[1]), Image.ANTIALIAS) #resizes file
  48.     file4 = ImageTk.PhotoImage(resized_file4)                    # loads the file and assigns it to a var
  49.     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
  50.     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
  51.     print("you clicked the button")
  52.  
  53.     twenty         = random.randint(0,20)
  54.     onehundred     = random.randint(0,100)
  55.     six            = random.randint(0,6)
  56.  
  57.     # Text for all cards.
  58.     left_lable          = tk.Label(frame_left, text="Main Card", bg="Green", fg="white",font=('Helvetica bold', 26))
  59.     center_lable        = tk.Label(frame_middle, text="Seccond Card.", bg="Green", fg="white",font=('Helvetica bold', 26))
  60.     right_label         = tk.Label(frame_right, text="Third card.", bg="Green", fg="white",font=('Helvetica bold', 26))
  61.    
  62.     roll_twenty         = tk.Label(menu, text=twenty, bg="Green", fg="white",font=('Helvetica bold', 26))
  63.     roll_onehundred     = tk.Label(menu, text=onehundred, bg="Green", fg="white",font=('Helvetica bold', 26))
  64.     roll_six            = tk.Label(menu, text=six, bg="Green", fg="white",font=('Helvetica bold', 26))
  65.    
  66.     roll_twenty.place(relx=0.05, rely=0.30)
  67.     roll_onehundred.place(relx=0.05, rely=0.40)
  68.     roll_six.place(relx=0.05, rely=0.50)
  69.  
  70.     left_lable.place(relx=0.3, rely=0.10)
  71.     center_lable.place(relx=0.21, rely=0.10)
  72.     right_label.place(relx=0.25, rely=0.10)
  73.    
  74.     root.mainloop()
  75.  
  76.  
  77.  
  78. print("remaking the box")
  79. new_card_button = tk.Button(menu, bg='lightblue', text='redraw card',font=('Helvetica bold', 15), command=randomCards)
  80. new_card_button.place(relx=0.05, rely=0.05, relwidth=0.40, relheight=0.07)
  81.  
  82.  
  83. root.mainloop()                                                   # Where the loop happens, all things happening to the window must be above
  84.  
  85.  
Add Comment
Please, Sign In to add comment