Hi I'm relatively new to python And now I've been asked to do a Ludo game using Tkinter module in it. I've tried my best and developed the board and a frame to roll dice. (I learned this can be made simpler using loops later) But the frame with dice is stuck beneath the board. I'll be thankful if you can correct my mistake and rectify me.
from tkinter import *
import random
ws = Tk()
ws.title('Ludo')
ws.geometry('1080x1000')
ws.config(bg='Black')
frame = Frame(ws, bg='Black')
Button(frame, text="", bg="White", height=2, width=3).grid(row=0, column=6)
Button(frame, text="", bg="White", height=2, width=3).grid(row=0, column=7)
Button(frame, text="", bg="White", height=2, width=3).grid(row=0, column=8)
Button(frame, text="", bg="White", height=2, width=3).grid(row=1, column=6)
Button(frame, text="", bg="Red", height=2, width=3).grid(row=1, column=7)
Button(frame, text="", bg="Red", height=2, width=3).grid(row=1, column=8)
Button(frame, text="", bg="White", height=2, width=3).grid(row=2, column=6)
Button(frame, text="", bg="Red", height=2, width=3).grid(row=2, column=7)
Button(frame, text="", bg="White", height=2, width=3).grid(row=2, column=8)
Button(frame, text="", bg="White", height=2, width=3).grid(row=3, column=6)
Button(frame, text="", bg="Red", height=2, width=3).grid(row=3, column=7)
Button(frame, text="", bg="White", height=2, width=3).grid(row=3, column=8)
Button(frame, text="", bg="White", height=2, width=3).grid(row=4, column=6)
Button(frame, text="", bg="Red", height=2, width=3).grid(row=4, column=7)
Button(frame, text="", bg="White", height=2, width=3).grid(row=4, column=8)
Button(frame, text="", bg="White", height=2, width=3).grid(row=5, column=6)
Button(frame, text="", bg="Red", height=2, width=3).grid(row=5, column=7)
Button(frame, text="", bg="White", height=2, width=3).grid(row=5, column=8)
Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=0)
Button(frame, text="", bg="Blue", height=2, width=3).grid(row=6, column=1)
Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=2)
Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=3)
Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=4)
Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=5)
Button(frame, text="", bg="White", height=2, width=3).grid(row=7, column=0)
Button(frame, text="", bg="Blue", height=2, width=3).grid(row=7, column=1)
Button(frame, text="", bg="Blue", height=2, width=3).grid(row=7, column=2)
Button(frame, text="", bg="Blue", height=2, width=3).grid(row=7, column=3)
Button(frame, text="", bg="Blue", height=2, width=3).grid(row=7, column=4)
Button(frame, text="", bg="Blue", height=2, width=3).grid(row=7, column=5)
Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=0)
Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=1)
Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=2)
Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=3)
Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=4)
Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=5)
Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=9)
Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=10)
Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=11)
Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=12)
Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=13)
Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=14)
Button(frame, text="", bg="Green", height=2, width=3).grid(row=7, column=9)
Button(frame, text="", bg="Green", height=2, width=3).grid(row=7, column=10)
Button(frame, text="", bg="Green", height=2, width=3).grid(row=7, column=11)
Button(frame, text="", bg="Green", height=2, width=3).grid(row=7, column=12)
Button(frame, text="", bg="Green", height=2, width=3).grid(row=7, column=13)
Button(frame, text="", bg="White", height=2, width=3).grid(row=7, column=14)
Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=9)
Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=10)
Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=11)
Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=12)
Button(frame, text="", bg="Green", height=2, width=3).grid(row=8, column=13)
Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=14)
Button(frame, text="", bg="White", height=2, width=3).grid(row=9, column=6)
Button(frame, text="", bg="#9932cc", height=2, width=3).grid(row=9, column=7)
Button(frame, text="", bg="White", height=2, width=3).grid(row=9, column=8)
Button(frame, text="", bg="White", height=2, width=3).grid(row=10, column=6)
Button(frame, text="", bg="#9932cc", height=2, width=3).grid(row=10, column=7)
Button(frame, text="", bg="White", height=2, width=3).grid(row=10, column=8)
Button(frame, text="", bg="White", height=2, width=3).grid(row=11, column=6)
Button(frame, text="", bg="#9932cc", height=2, width=3).grid(row=11, column=7)
Button(frame, text="", bg="White", height=2, width=3).grid(row=11, column=8)
Button(frame, text="", bg="White", height=2, width=3).grid(row=12, column=6)
Button(frame, text="", bg="#9932cc", height=2, width=3).grid(row=12, column=7)
Button(frame, text="", bg="White", height=2, width=3).grid(row=12, column=8)
Button(frame, text="", bg="#9932cc", height=2, width=3).grid(row=13, column=6)
Button(frame, text="", bg="#9932cc", height=2, width=3).grid(row=13, column=7)
Button(frame, text="", bg="White", height=2, width=3).grid(row=13, column=8)
Button(frame, text="", bg="White", height=2, width=3).grid(row=14, column=6)
Button(frame, text="", bg="White", height=2, width=3).grid(row=14, column=7)
Button(frame, text="", bg="White", height=2, width=3).grid(row=14, column=8)
Button(frame, text=" a ", bg="#00bfff", height=2, width=3).grid(row=1, column=1)
Button(frame, text=" b ", bg="#00bfff", height=2, width=3).grid(row=1, column=4)
Button(frame, text=" c ", bg="#00bfff", height=2, width=3).grid(row=4, column=1)
Button(frame, text=" d ", bg="#00bfff", height=2, width=3).grid(row=4, column=4)
Button(frame, text=" a ", bg="#ff355e", height=2, width=3).grid(row=1, column=10)
Button(frame, text=" b ", bg="#ff355e", height=2, width=3).grid(row=1, column=13)
Button(frame, text=" c ", bg="#ff355e", height=2, width=3).grid(row=4, column=10)
Button(frame, text=" d ", bg="#ff355e", height=2, width=3).grid(row=4, column=13)
Button(frame, text=" a ", bg="#dda0dd", height=2, width=3).grid(row=10, column=1)
Button(frame, text=" b ", bg="#dda0dd", height=2, width=3).grid(row=10, column=4)
Button(frame, text=" c ", bg="#dda0dd", height=2, width=3).grid(row=13, column=1)
Button(frame, text=" d ", bg="#dda0dd", height=2, width=3).grid(row=13, column=4)
Button(frame, text=" a ", bg="#39ff14", height=2, width=3).grid(row=10, column=10)
Button(frame, text=" b ", bg="#39ff14", height=2, width=3).grid(row=10, column=13)
Button(frame, text=" c ", bg="#39ff14", height=2, width=3).grid(row=13, column=10)
Button(frame, text=" d ", bg="#39ff14", height=2, width=3).grid(row=13, column=13)
Button(frame, height=2, width=3, bg='yellow').grid(row=6, column=6)
Button(frame, height=2, width=3, bg='yellow').grid(row=7, column=6)
Button(frame, height=2, width=3, bg='yellow').grid(row=8, column=6)
Button(frame, height=2, width=3, bg='yellow').grid(row=6, column=7)
Button(frame, text="Win", bg='orange', height=2, width=3).grid(row=7, column=7)
Button(frame, height=2, width=3, bg='yellow').grid(row=8, column=7)
Button(frame, height=2, width=3, bg='yellow').grid(row=6, column=8)
Button(frame, height=2, width=3, bg='yellow').grid(row=7, column=8)
Button(frame, height=2, width=3, bg='yellow').grid(row=8, column=8)
Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=0)
Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=1)
Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=2)
Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=3)
Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=4)
Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=5)
Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=0)
Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=2)
Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=3)
Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=5)
Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=0)
Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=1)
Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=2)
Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=3)
Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=4)
Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=5)
Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=0)
Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=1)
Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=2)
Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=3)
Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=4)
Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=5)
Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=0)
Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=2)
Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=3)
Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=5)
Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=0)
Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=1)
Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=2)
Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=3)
Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=4)
Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=5)
Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=9)
Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=10)
Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=11)
Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=12)
Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=13)
Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=14)
Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=9)
Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=11)
Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=12)
Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=14)
Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=9)
Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=10)
Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=11)
Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=12)
Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=13)
Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=14)
Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=9)
Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=10)
Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=11)
Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=12)
Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=13)
Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=14)
Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=9)
Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=11)
Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=12)
Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=14)
Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=9)
Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=10)
Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=11)
Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=12)
Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=13)
Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=14)
Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=0)
Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=1)
Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=2)
Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=3)
Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=4)
Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=5)
Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=0)
Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=2)
Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=3)
Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=5)
Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=0)
Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=1)
Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=2)
Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=3)
Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=4)
Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=5)
Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=0)
Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=1)
Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=2)
Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=3)
Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=4)
Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=5)
Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=0)
Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=2)
Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=3)
Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=5)
Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=0)
Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=1)
Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=2)
Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=3)
Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=4)
Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=5)
Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=9)
Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=10)
Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=11)
Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=12)
Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=13)
Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=14)
Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=9)
Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=11)
Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=12)
Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=14)
Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=9)
Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=10)
Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=11)
Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=12)
Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=13)
Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=14)
Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=9)
Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=10)
Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=11)
Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=12)
Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=13)
Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=14)
Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=9)
Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=11)
Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=12)
Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=14)
Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=9)
Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=10)
Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=11)
Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=12)
Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=13)
Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=14)
frame.pack(expand=True)
def roll_dice():
dice_codes = ['\u2680', '\u2681',
'\u2682', '\u2683',
'\u2684', '\u2685']
numbers = {'\u2680': 1, '\u2681': 2,
'\u2682': 3, '\u2683': 4,
'\u2684': 5, '\u2685': 6}
d = random.choice(dice_codes)
if d in numbers.keys():
d_number = numbers[d]
dice.config(text=d)
dice_number.config(text=d_number)
total_numbers.config(text=f'You Rolled: {d_number}')
frame= Frame(ws)
frame.pack(expand=True)
dice = Label(frame, font=('ariel', 150), fg='black')
dice.grid(row=0, column=20, padx=5)
dice_number = Label(frame, font=('ariel', 20))
dice_number.grid(row=1, column=20)
button = Button(ws, text='Roll Dice', font=('ariel', 24),
relief=GROOVE, bg='grey', command=roll_dice)
button.pack(pady=20)
total_numbers = Label(ws, text='', font=('ariel', 24))
total_numbers.pack(pady=10)
roll_dice()
ws.mainloop()
CodePudding user response:
Solution
The packer can take a side
option. The values can be left
, right
, top
, bottom
, etc. By default its set to top
. You can use either of right
and left
. Add it for both frames.
frame.pack(expand=True, side=tk.LEFT)
Reference
Complete code
# try not to import globally
import tkinter as tk
from tkinter.constants import *
import random
ws = tk.Tk()
ws.title('Ludo')
ws.geometry('1080x1000')
ws.config(bg='Black')
frame = tk.Frame(ws, bg='Black')
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=0, column=6)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=0, column=7)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=0, column=8)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=1, column=6)
tk.Button(frame, text="", bg="Red", height=2, width=3).grid(row=1, column=7)
tk.Button(frame, text="", bg="Red", height=2, width=3).grid(row=1, column=8)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=2, column=6)
tk.Button(frame, text="", bg="Red", height=2, width=3).grid(row=2, column=7)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=2, column=8)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=3, column=6)
tk.Button(frame, text="", bg="Red", height=2, width=3).grid(row=3, column=7)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=3, column=8)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=4, column=6)
tk.Button(frame, text="", bg="Red", height=2, width=3).grid(row=4, column=7)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=4, column=8)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=5, column=6)
tk.Button(frame, text="", bg="Red", height=2, width=3).grid(row=5, column=7)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=5, column=8)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=0)
tk.Button(frame, text="", bg="Blue", height=2, width=3).grid(row=6, column=1)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=2)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=3)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=4)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=5)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=7, column=0)
tk.Button(frame, text="", bg="Blue", height=2, width=3).grid(row=7, column=1)
tk.Button(frame, text="", bg="Blue", height=2, width=3).grid(row=7, column=2)
tk.Button(frame, text="", bg="Blue", height=2, width=3).grid(row=7, column=3)
tk.Button(frame, text="", bg="Blue", height=2, width=3).grid(row=7, column=4)
tk.Button(frame, text="", bg="Blue", height=2, width=3).grid(row=7, column=5)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=0)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=1)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=2)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=3)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=4)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=5)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=9)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=10)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=11)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=12)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=13)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=6, column=14)
tk.Button(frame, text="", bg="Green", height=2, width=3).grid(row=7, column=9)
tk.Button(frame, text="", bg="Green", height=2, width=3).grid(row=7, column=10)
tk.Button(frame, text="", bg="Green", height=2, width=3).grid(row=7, column=11)
tk.Button(frame, text="", bg="Green", height=2, width=3).grid(row=7, column=12)
tk.Button(frame, text="", bg="Green", height=2, width=3).grid(row=7, column=13)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=7, column=14)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=9)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=10)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=11)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=12)
tk.Button(frame, text="", bg="Green", height=2, width=3).grid(row=8, column=13)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=8, column=14)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=9, column=6)
tk.Button(frame, text="", bg="#9932cc", height=2, width=3).grid(row=9, column=7)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=9, column=8)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=10, column=6)
tk.Button(frame, text="", bg="#9932cc", height=2, width=3).grid(row=10, column=7)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=10, column=8)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=11, column=6)
tk.Button(frame, text="", bg="#9932cc", height=2, width=3).grid(row=11, column=7)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=11, column=8)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=12, column=6)
tk.Button(frame, text="", bg="#9932cc", height=2, width=3).grid(row=12, column=7)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=12, column=8)
tk.Button(frame, text="", bg="#9932cc", height=2, width=3).grid(row=13, column=6)
tk.Button(frame, text="", bg="#9932cc", height=2, width=3).grid(row=13, column=7)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=13, column=8)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=14, column=6)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=14, column=7)
tk.Button(frame, text="", bg="White", height=2, width=3).grid(row=14, column=8)
tk.Button(frame, text=" a ", bg="#00bfff", height=2, width=3).grid(row=1, column=1)
tk.Button(frame, text=" b ", bg="#00bfff", height=2, width=3).grid(row=1, column=4)
tk.Button(frame, text=" c ", bg="#00bfff", height=2, width=3).grid(row=4, column=1)
tk.Button(frame, text=" d ", bg="#00bfff", height=2, width=3).grid(row=4, column=4)
tk.Button(frame, text=" a ", bg="#ff355e", height=2, width=3).grid(row=1, column=10)
tk.Button(frame, text=" b ", bg="#ff355e", height=2, width=3).grid(row=1, column=13)
tk.Button(frame, text=" c ", bg="#ff355e", height=2, width=3).grid(row=4, column=10)
tk.Button(frame, text=" d ", bg="#ff355e", height=2, width=3).grid(row=4, column=13)
tk.Button(frame, text=" a ", bg="#dda0dd", height=2, width=3).grid(row=10, column=1)
tk.Button(frame, text=" b ", bg="#dda0dd", height=2, width=3).grid(row=10, column=4)
tk.Button(frame, text=" c ", bg="#dda0dd", height=2, width=3).grid(row=13, column=1)
tk.Button(frame, text=" d ", bg="#dda0dd", height=2, width=3).grid(row=13, column=4)
tk.Button(frame, text=" a ", bg="#39ff14", height=2, width=3).grid(row=10, column=10)
tk.Button(frame, text=" b ", bg="#39ff14", height=2, width=3).grid(row=10, column=13)
tk.Button(frame, text=" c ", bg="#39ff14", height=2, width=3).grid(row=13, column=10)
tk.Button(frame, text=" d ", bg="#39ff14", height=2, width=3).grid(row=13, column=13)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=6, column=6)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=7, column=6)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=8, column=6)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=6, column=7)
tk.Button(frame, text="Win", bg='orange', height=2, width=3).grid(row=7, column=7)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=8, column=7)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=6, column=8)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=7, column=8)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=8, column=8)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=0)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=1)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=2)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=3)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=4)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=5)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=0)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=2)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=3)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=5)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=0)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=1)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=2)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=3)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=4)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=5)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=0)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=1)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=2)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=3)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=4)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=5)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=0)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=2)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=3)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=5)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=0)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=1)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=2)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=3)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=4)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=5)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=9)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=10)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=11)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=12)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=13)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=0, column=14)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=9)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=11)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=12)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=1, column=14)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=9)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=10)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=11)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=12)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=13)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=2, column=14)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=9)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=10)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=11)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=12)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=13)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=3, column=14)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=9)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=11)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=12)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=4, column=14)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=9)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=10)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=11)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=12)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=13)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=5, column=14)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=0)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=1)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=2)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=3)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=4)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=5)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=0)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=2)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=3)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=5)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=0)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=1)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=2)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=3)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=4)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=5)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=0)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=1)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=2)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=3)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=4)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=5)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=0)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=2)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=3)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=5)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=0)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=1)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=2)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=3)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=4)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=5)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=9)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=10)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=11)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=12)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=13)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=9, column=14)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=9)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=11)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=12)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=10, column=14)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=9)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=10)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=11)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=12)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=13)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=11, column=14)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=9)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=10)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=11)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=12)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=13)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=12, column=14)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=9)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=11)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=12)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=13, column=14)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=9)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=10)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=11)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=12)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=13)
tk.Button(frame, height=2, width=3, bg='yellow').grid(row=14, column=14)
frame.pack(expand=True, side=LEFT)
def roll_dice():
dice_codes = ['\u2680', '\u2681',
'\u2682', '\u2683',
'\u2684', '\u2685']
numbers = {'\u2680': 1, '\u2681': 2,
'\u2682': 3, '\u2683': 4,
'\u2684': 5, '\u2685': 6}
d = random.choice(dice_codes)
if d in numbers.keys():
d_number = numbers[d]
dice.config(text=d)
dice_number.config(text=d_number)
total_numbers.config(text=f'You Rolled: {d_number}')
frame= tk.Frame(ws)
frame.pack(expand=True, side=LEFT)
dice = tk.Label(frame, font=('ariel', 150), fg='black')
dice.grid(row=0, column=20, padx=5)
dice_number = tk.Label(frame, font=('ariel', 20))
dice_number.grid(row=1, column=20)
button = tk.Button(ws, text='Roll Dice', font=('ariel', 24),
relief=GROOVE, bg='grey', command=roll_dice)
button.pack(pady=20)
total_numbers = tk.Label(ws, text='', font=('ariel', 24))
total_numbers.pack(pady=10)
roll_dice()
ws.mainloop()
CodePudding user response:
Please can you help me with this I need the dice-box on side of the board, roll dice button beneath this dice-box, and result beneath this, Also I need another label stating "player 1 turn"/"player 2 turn"/"player 3 turn"/"player 4 turn" I'm really blank on how to do such alignments in this as I'm using tkinter module for the first time. I'll be thankful if you could help me with this project.