Python Forum
A sign-Reversal Puzzle - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: A sign-Reversal Puzzle (/thread-22959.html)



A sign-Reversal Puzzle - HY2000 - Dec-05-2019

I am creating a sign-reversal puzzle. That should have a 6x6 array with an initial value given. Player need to choose a row to reverse the sign in each turn and game will sum the column. The game ends if the player could change the row sums and column sums to non-negative values if the initial ones are not all non-negative value.

However, it is hard to start. I have built a welcome page of the game... And somehow I think I am not doing it in the right way, I really need some help! Below are my codes for the welcome page I built.

from tkinter import *

from tkinter import messagebox

top = Tk()
top.geometry("500x500")

#   def header():
#   messagebox.showinfo("Welcome to Sign-Reversal Puzzle game", "Hello players!")

w = Label (top, text = "Welcome to Sign-Reversal Puzzle game!")
w.pack()

def play():
   messagebox.showinfo("Play game", "This is the game")

def instruction():
   messagebox.showinfo("Instruction", "The game rules are as below: ")
   messagebox.showinfo("First Step", "Given a 6x6 array with values, player need to choose a row to change sign")
   messagebox.showinfo("Second Step", "After changing the sign, we will change sum the rows and columns")
   messagebox.showinfo("How to win?", "Have all row sums and column sums to non-negative values")


B1 = Button(top, text = "Welcome to Sign-Reversal Puzzle game", command = header)
B1.place(x = 100,y = 10)

B2 = Button(top, text = "Play game", command = play)
B2.place(x = 35, y = 60)

B3 = Button(top, text = "Instruction", command = instruction)
B3.place(x = 35, y = 90)

top.mainloop()



RE: A sign-Reversal Puzzle - Larz60+ - Dec-05-2019

missing header and shouldn't be a function (as in you're commented out line 8)


RE: A sign-Reversal Puzzle - HY2000 - Dec-05-2019

Yes, I comment it wrongly. I should comment the codes in line 11-12. After I correct the comment it is executable. But it is the right way to build a game welcome page?