The Wayback Machine - https://web.archive.org/web/20241126094218/https://www.geeksforgeeks.org/python-simple-flames-game-using-tkinter/
Open In App

Python | Simple FLAMES game using Tkinter

Last Updated : 10 Jun, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Prerequisites: 

Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to create GUI applications. Now, it’s up to the imagination or necessity of the developer, what he/she wants to develop using this toolkit. 
To create a Tkinter : 

  • Importing the module – Tkinter
  • Create the main window (container)
  • Add any number of widgets to the main window.
  • Apply the event Trigger on the widgets

The GUI would look like below:

Let’s create a GUI version of a simple FLAMES game.FLAMES is a popular game named after the acronym: Friends, Lovers, Affectionate, Marriage, Enemies, Sibling. This game does not accurately predict whether an individual is right for you, but it can be fun to play this with your friends.
 

Below is the implementation :
 

Python3




# import all functions from the tkinter
from tkinter import *
 
# function for removing common characters
# with their respective occurrences
def remove_match_char(list1, list2):
 
    for i in range(len(list1)) :
        for j in range(len(list2)) :
 
            # if common character is found
            # then remove that character
            # and return list of concatenated
            # list with True Flag
            if list1[i] == list2[j] :
                c = list1[i]
 
                # remove character from the list
                list1.remove(c)
                list2.remove(c)
 
                # concatenation of two list elements with *
                # * is act as border mark here
                list3 = list1 + ["*"] + list2
 
                # return the concatenated list with True flag
                return [list3, True]
 
    # no common characters is found
    # return the concatenated list with False flag
    list3 = list1 + ["*"] + list2
    return [list3, False]
 
 
# function for telling the relationship status
def tell_status() :
     
    # take a 1st player name from Player1_field entry box 
    p1 = Player1_field.get()
 
    # converted all letters into lower case
    p1 = p1.lower()
 
    # replace any space with empty string
    p1.replace(" ", "")
 
    # make a list of letters or characters
    p1_list = list(p1)
 
    # take a 2nd player name from Player2_field entry box
    p2 = Player2_field.get()
    p2 = p2.lower()
    p2.replace(" ", "")
    p2_list = list(p2)
 
    # taking a flag as True initially
    proceed = True
     
    # keep calling remove_match_char function
    # until common characters is found or
    # keep looping until proceed flag is True
    while proceed :
 
        # function calling and store return value
        ret_list = remove_match_char(p1_list, p2_list)
 
        # take out concatenated list from return list
        con_list = ret_list[0]
 
        # take out flag value from return list
        proceed = ret_list[1]
 
        # find the index of "*" / border mark
        star_index = con_list.index("*")
 
        # list slicing perform
         
        # all characters before * store in p1_list
        p1_list = con_list[ : star_index]
 
        # all characters after * store in p2_list
        p2_list = con_list[star_index + 1 : ]
 
 
    # count total remaining characters
    count = len(p1_list) + len(p2_list)
 
    # list of FLAMES acronym
    result = ["Friends", "Love", "Affection", "Marriage", "Enemy", "Siblings"]
 
    # keep looping until only one item
    # is not remaining in the result list
    while len(result) > 1 :
 
        # store that index value from
        # where we have to perform slicing.
        split_index = (count % len(result) - 1)
 
        # this steps is done for performing
        # anticlock-wise circular fashion counting.
        if split_index >= 0 :
 
            # list slicing
            right = result[split_index + 1 : ]
            left = result[ : split_index]
 
            # list concatenation
            result = right + left
 
        else :
            result = result[ : len(result) - 1]
 
    # insert method inserting the 
        # value in the text entry box.
    Status_field.insert(10, result[0])
 
 
# Function for clearing the 
# contents of all text entry boxes  
def clear_all() : 
    Player1_field.delete(0, END)  
    Player2_field.delete(0, END)
    Status_field.delete(0, END)
   
    # set focus on the Player1_field entry box 
    Player1_field.focus_set() 
 
 
# Driver code
if __name__ == "__main__" :
   
    # Create a GUI window
    root = Tk()
   
    # Set the background colour of GUI window
    root.configure(background = 'light green')
   
    # Set the configuration of GUI window
    root.geometry("350x125")
   
    # set the name of tkinter GUI window
    root.title("Flames Game") 
       
    # Create a Player 1 Name: label
    label1 = Label(root, text = "Player 1 Name: ",
                   fg = 'black', bg = 'dark green')
   
    # Create a Player 2 Name: label
    label2 = Label(root, text = "Player 2 Name: ",
                   fg = 'black', bg = 'dark green')
       
    # Create a Relation Status: label
    label3 = Label(root, text = "Relationship Status: ",
                   fg = 'black', bg = 'red')
 
    # grid method is used for placing 
    # the widgets at respective positions 
    # in table like structure .
    label1.grid(row = 1, column = 0, sticky ="E") 
    label2.grid(row = 2, column = 0, sticky ="E") 
    label3.grid(row = 4, column = 0, sticky ="E")
 
    # Create a text entry box 
    # for filling or typing the information.
    Player1_field = Entry(root) 
    Player2_field = Entry(root) 
    Status_field = Entry(root)
 
    # grid method is used for placing 
    # the widgets at respective positions 
    # in table like structure . 
    # ipadx keyword argument set width of entry space . 
    Player1_field.grid(row = 1, column = 1, ipadx ="50") 
    Player2_field.grid(row = 2, column = 1, ipadx ="50") 
    Status_field.grid(row = 4, column = 1, ipadx ="50") 
 
    # Create a Submit Button and attached 
    # to tell_status function 
    button1 = Button(root, text = "Submit", bg = "red", 
                     fg = "black", command = tell_status)
   
    # Create a Clear Button and attached 
    # to clear_all function 
    button2 = Button(root, text = "Clear", bg = "red", 
                     fg = "black", command = clear_all)
 
    # grid method is used for placing 
    # the widgets at respective positions 
    # in table like structure . 
    button1.grid(row = 3, column = 1)
    button2.grid(row = 5, column = 1)
 
    # Start the GUI 
    root.mainloop()


Output : 
 



Previous Article
Next Article

Similar Reads

Python | Program to implement simple FLAMES game
Python is a multipurpose language and one can do literally anything with it. Python can also be used for game development. Let’s create a simple FLAMES game without using any external game libraries like PyGame. FLAMES is a popular game named after the acronym: Friends, Lovers, Affectionate, Marriage, Enemies, Sibling. This game does not accurately
6 min read
PyQt5 - Flames Calculator
In this article we will see how we can create a flames calculator using PyQt5. This flames calculator assesses and predicts the outcome of a relationship based on an algorithm of two given names.FLAMES is a popular game named after the acronym: Friends, Lovers, Affectionate, Marriage, Enemies, Sibling. This game does not accurately predict whether
11 min read
Difference Between The Widgets Of Tkinter And Tkinter.Ttk In Python
Python offers a variety of GUI (Graphical User Interface) frameworks to develop desktop applications. Among these, Tkinter is the standard Python interface to the Tk GUI toolkit. Tkinter also includes the 'ttk' module, which enhances the visual appeal and functionality of the applications. In this article, we will cover the differences, providing a
4 min read
Simple registration form using Python Tkinter
Prerequisites: Tkinter Introduction, openpyxl module.Python provides the Tkinter toolkit to develop GUI applications. Now, it’s upto the imagination or necessity of developer, what he/she want to develop using this toolkit. Let's make a simple information form GUI application using Tkinter. In this application, User has to fill up the required info
5 min read
Python | Simple GUI calculator using Tkinter
Prerequisite: Tkinter Introduction, lambda function Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to create GUI a
6 min read
Python | Simple calculator using Tkinter
Prerequisite : Tkinter IntroductionPython offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest way to create the GUI applications. Cr
3 min read
Color game using Tkinter in Python
TKinter is widely used for developing GUI applications. Along with applications, we can also use Tkinter GUI to develop games. Let's try to make a game using Tkinter. In this game player has to enter color of the word that appears on the screen and hence the score increases by one, the total time to play this game is 30 seconds. Colors used in this
4 min read
Tic Tac Toe game with GUI using tkinter in Python
Tic-tac-toe (American English), noughts and crosses (British English), or Xs and Os is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner. tkinter Python library is used to create the GUI.
15+ min read
Python - MCQ Quiz Game using Tkinter
Prerequisite: Python GUI – tkinter Python provides a standard GUI framework Tkinter which is used to develop fast and easy GUI applications. Here we will be developing a simple multiple-choice quiz in python with GUI. We will be creating a multiple choice quiz in Python with Tkinter. First, we will create a library named Quiz in the directory of yo
6 min read
Snake Game Using Tkinter - Python
For many years, players all across the world have cherished the iconic video game Snake. The player controls a snake that crawls around the screen while attempting to consume food, avoiding obstacles or running into its own tail. It is a straightforward but addictive game. The snake lengthens each time it consumes food, and the player must control
12 min read
Number Guessing Game Using Python Tkinter Module
Number Guessing Game using the Python Tkinter module is a simple game that involves guessing a randomly generated number. The game is developed using the Tkinter module, which provides a graphical user interface for the game. The game has a start button that starts the game and a text entry field where the user can enter their guess. The game also
5 min read
Python | Tkinter ttk.Checkbutton and comparison with simple Checkbutton
Tkinter is a GUI (Graphical User Interface) module which comes along with the Python itself. This module is widely used to create GUI applications. tkinter.ttk is used to create the GUI applications with the effects of modern graphics which cannot be achieved using only tkinter. Checkbutton is used to select multiple options. Checkbuttons can be cr
2 min read
Rock Paper and Scissor Game Using Tkinter
Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter is the fastest and easiest way to create GUI applications. Prerequisite: Tkinter, random In this articl
7 min read
Create a Simple Two Player Game using Turtle in Python
Prerequisites: Turtle Programming in Python TurtleMove game is basically a luck-based game. In this game two-players (Red & Blue), using their own turtle (object) play the game. How to play The game is played in the predefined grid having some boundaries. Both players move the turtle for a unit distance.Now both players flip the coin:if HEAD, t
4 min read
A simple News app with Tkinter and Newsapi
Prerequisites: Tkinter Tkinter is a very famous python library for building a desktop app for windows and UNIX based OS. The idea here is to generate a python code to build a news app with Tkinter. You can very easily get yourself an API key from newsapi.org . ApproachImport modulesCreate a screen with a titleAdd labelsAdd buttonsCreate a textarea
3 min read
Why is this simple Tkinter UI not displaying the specified label
Creating user interfaces with Tkinter in Python is a popular choice due to its simplicity and ease of use. However, even simple Tkinter applications can sometimes have issues that prevent them from working as expected. One common problem is when a specified label does not display on the UI. This article will explore potential reasons for this issue
3 min read
Python | Message Encode-Decode using Tkinter
Prerequisite : Basics of TkinterPython offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest way to create the GUI applications. Python pr
5 min read
Python | Distance-time GUI calculator using Tkinter
Prerequisites : Introduction to Tkinter | Using google distance matrix API Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest wa
7 min read
Python | Random Password Generator using Tkinter
With growing technology, everything has relied on data, and securing this data is the main concern. Passwords are meant to keep the data safe that we upload on the Internet. An easy password can be hacked easily and all personal information can be misused. In order to prevent such things and keep the data safe, it is necessary to keep our passwords
4 min read
How to visualize selection and insertion sort using Tkinter in Python?
In this article, we are going to create a GUI application that will make us visualize and understand two of the most popular sorting algorithms better, using Tkinter module. Those two sorting algorithms are selection sort and insertion sort. Selection sort and Insertion sort are the two most popular algorithms. Selection sort is a comparison-based
6 min read
Python | Real time currency converter using Tkinter
Prerequisites : Introduction to tkinter | Get the real time currency exchange ratePython offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and
4 min read
Python | Real time weather detection using Tkinter
Prerequisites : Introduction to tkinter | Find current weather of any cityPython offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest
5 min read
Python | Create a digital clock using Tkinter
As we know Tkinter is used to create a variety of GUI (Graphical User Interface) applications. In this article we will learn how to create a Digital clock using Tkinter. Prerequisites: Python functions Tkinter basics (Label Widget) Time module https://www.youtube.com/watch?v=1INA9AmaDtQ Using Label widget from Tkinter and time module: In the follow
2 min read
Python | Loan calculator using Tkinter
Prerequisite: Tkinter Introduction Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to create GUI applications. Creati
5 min read
Getting screen's height and width using Tkinter | Python
Tkinter provides some methods with the help of which we can get the current screen height and width.Following methods can be used to decide height and width : winfo_screenheight() // Returns screen height in pixels winfo_screenmmheight() // Returns screen height in mm winfo_screenwidth() // Returns screen width in pixels winfo_screenmmwidth() // Re
1 min read
Python Tkinter | Moving objects using Canvas.move() method
The Canvas class of Tkinter supports functions that are used to move objects from one position to another in any canvas or Tkinter top-level. Syntax: Canvas.move(canvas_object, x, y)Parameters: canvas_object is any valid image or drawing created with the help of Canvas class. To know how to create object using Canvas class take reference of this. x
2 min read
Python Tkinter | Create different type of lines using Canvas class
In Tkinter, Canvas.create_line() method is used to create lines in any canvas. These lines can only be seen on canvas so first, you need to create a Canvas object and later pack it into the main window. Syntax: Canvas.create_line(x1, y1, x2, y2, ...., options = ...) Note: Minimum of 4 points are required to create a line, but you can also add multi
2 min read
Python Tkinter | Create different shapes using Canvas class
In Tkinter, Canvas class is used to create different shapes with the help of some functions which are defined under Canvas class. Any shape that Canvas class creates requires a canvas, so before creating any shapes a Canvas object is required and needs to be packed to the main window. Canvas Methods for shapes: Canvas.create_oval(x1, y1, x2, y2, op
3 min read
Python | Create a GUI Marksheet using Tkinter
Create a python GUI mark sheet. Where credits of each subject are given, enter the grades obtained in each subject and click on Submit. The credits per subject, the total credits as well as the SGPA are displayed after being calculated automatically. Use Tkinter to create the GUI interface. Refer the below articles to get the idea about basics of t
8 min read
Python: Age Calculator using Tkinter
Prerequisites :Introduction to tkinter Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to create GUI applications.
5 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg