how to create ludo game using python and Tkinter - Second Part

Posted by Suraj Singh on June 20, 2017 · 6 mins read

hii readers,

This Is Our Second Part Of Our Ludo Game Tutorial And In This Part, I Am Going To Write About how To Create Ludo Game Using Python And Tkinter Module.

If You Are A New Reader Then Check Our Previous Tutorial Click Here

In Today's Post We are Going To write Script For Our Ludo Game. As I Already Described In My Previous Tutorial, To Run This Game First We will Create A Grid Of Squares In Tkinter Canvas That Will Act as A Ground Level Track For Our Tokens And Then We Will Create Different Roots For Our Tokens To Run On This Main Track According To Ludo Game Rules. So, Here I Am Writing a views Script Of Ludo Game To Manage All Of These process In Simple Manners.

And To Run This Script, First We Need To Import GameConfig And Models (Described In Previous Tutorials)


# Import Module
import Tkinter
import tkinter as Tkinter

from GameConfig import *
from models import *

# Main Class For Canvas Widget
class Board(Tkinter.Canvas):
def __init__(self, *args, **kwargs):
Tkinter.Canvas.__init__(self, *args, **kwargs)
self.configure(width=S_WIDTH*AREA, height=S_HEIGHT*AREA)

# Filling Colors In Boxes
def highlight(self):

# Main Tracks
for c in TRACK:
self.itemconfigure(c, fill=C_0_D, activewidth=2, activefill=C_0_A, activeoutline="black")

# Ending Tracks
for n,k in enumerate(F_TRACK):
for j in k:
self.itemconfigure(j, fill=COLOR[n], activewidth=2, activeoutline='black')

# Stations
for n,s in enumerate(STATIONS):
for j,c in enumerate(s):
self.itemconfigure(c, fill=COLOR[n], activewidth=2)
coordinates = self.coords(c)
#store=self.create_oval(*coordinates, fill=COLOR[n], width=3, tag="COIN{}{}".format(n,j))
# print n,s,j,c

# Stops
for s in STOPS:
self.itemconfigure(s, fill="gray58", activefill="gray70", activewidth=3, activeoutline="gray10")

# Creating Square Boxes
def create_squares(self):
for i in range(AREA):
for j in range(AREA):
self.create_rectangle(S_WIDTH*i, S_HEIGHT*j, (S_WIDTH*i)+S_WIDTH,(S_HEIGHT*j)+S_HEIGHT, tag="{}.{}".format(i,j), outline='white', fill="ivory")
# self.create_text(S_WIDTH*i+20, S_HEIGHT*j+20, text="{}.{}".format(i,j))

# main Trigger
if __name__=="__main__":
root = Tkinter.Tk()
c = Board(root, width=S_WIDTH*AREA, height=S_HEIGHT*AREA)
c.pack(expand=True, fill="both")

For Downloading These Example Codes Click Here

For Previous Tutorial Click Here

And In Our Next Tutorial, We Will Continue This Tutorial.

Thanks For Reading
Have A Nice Day.