|
| 1 | +from tkinter import * |
| 2 | + |
| 3 | + |
| 4 | +def clear_all(): |
| 5 | + Player1_field.delete(0, END) |
| 6 | + Player2_field.delete(0, END) |
| 7 | + Status_field.delete(0, END) |
| 8 | + # set focus on the Player1_field entry box |
| 9 | + Player1_field.focus_set() |
| 10 | + |
| 11 | + |
| 12 | +def tell_status(): |
| 13 | + p1 = Player1_field.get() |
| 14 | + p2 = Player2_field.get() |
| 15 | + p1 = p1.replace(" ", "") |
| 16 | + p2 = p2.replace(" ", "") |
| 17 | + p1 = list(p1) |
| 18 | + p2 = list(p2) |
| 19 | + |
| 20 | + Status_field.insert(10, result_flame(p1, p2)) |
| 21 | + |
| 22 | + |
| 23 | +def result_flame(x, y): |
| 24 | + for i in x[:]: |
| 25 | + if i in y: |
| 26 | + x.remove(i) |
| 27 | + y.remove(i) |
| 28 | + count = len(x) + len(y) |
| 29 | + result = ["Friends", "Love", "Affection", "Marriage", "Enemy", "Siblings"] |
| 30 | + while len(result) > 1: |
| 31 | + split_index = (count % len(result) - 1) |
| 32 | + if (split_index >= 0): |
| 33 | + right = result[split_index + 1:] |
| 34 | + left = result[: split_index] |
| 35 | + result = right + left |
| 36 | + else: |
| 37 | + result = result[: len(result) - 1] |
| 38 | + return result |
| 39 | + |
| 40 | + |
| 41 | +if __name__ == "__main__": |
| 42 | + # Create a GUI window |
| 43 | + root = Tk() |
| 44 | + # Set the background colour of GUI window |
| 45 | + root.configure(background='light pink') |
| 46 | + # Set the configuration of GUI window |
| 47 | + root.geometry("350x125") |
| 48 | + # set the name of tkinter GUI window |
| 49 | + root.title("Flames Game") |
| 50 | + # Create a Player 1 Name: label |
| 51 | + label1 = Label(root, text="Name 1 ", fg='black', bg='light green') |
| 52 | + # Create a Player 2 Name: label |
| 53 | + label2 = Label(root, text="Name 2 ", fg='black', bg='light blue') |
| 54 | + # Create a Relation Status: label |
| 55 | + label3 = Label(root, text="Relationship Status", fg='black', bg='#FFE4C4') |
| 56 | + # grid method is used for placing |
| 57 | + # the widgets at respective positions |
| 58 | + # in table like structure. |
| 59 | + label1.grid(row=1, column=0, sticky="E") |
| 60 | + label2.grid(row=2, column=0, sticky="E") |
| 61 | + label3.grid(row=4, column=0, sticky="E") |
| 62 | + # Create a text entry box |
| 63 | + # for filling or typing the information. |
| 64 | + Player1_field = Entry(root) |
| 65 | + Player2_field = Entry(root) |
| 66 | + Status_field = Entry(root) |
| 67 | + # grid method is used for placing |
| 68 | + # the widgets at respective positions |
| 69 | + # in table like structure. |
| 70 | + # ipadx keyword argument set width of entry space. |
| 71 | + Player1_field.grid(row=1, column=1, ipadx="50") |
| 72 | + Player2_field.grid(row=2, column=1, ipadx="50") |
| 73 | + Status_field.grid(row=4, column=1, ipadx="50") |
| 74 | + # Create a Submit Button and attached |
| 75 | + # to tell_status function |
| 76 | + button1 = Button(root, text="Flame", bg="#FF7F50", |
| 77 | + fg="black", command=tell_status) |
| 78 | + |
| 79 | + # Create a Clear Button and attached |
| 80 | + # to clear_all function |
| 81 | + button2 = Button(root, text="Clear", bg="#CD5C5C", |
| 82 | + fg="black", command=clear_all) |
| 83 | + |
| 84 | + # grid method is used for placing |
| 85 | + # the widgets at respective positions |
| 86 | + # in table like structure. |
| 87 | + button1.grid(row=3, column=1) |
| 88 | + button2.grid(row=5, column=1) |
| 89 | + |
| 90 | + # Start the GUI |
| 91 | + root.mainloop() |
0 commit comments