Skip to content

Commit

Permalink
Button position adjusted for '600x600' window size
Browse files Browse the repository at this point in the history
  • Loading branch information
devrajneupane committed Aug 7, 2021
1 parent 71399ce commit 7d83cba
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 49 deletions.
6 changes: 3 additions & 3 deletions Chain_Reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def home_page():
widget_destroy(root)
image_frame()
button_frame = ttk.Frame(root, relief="raised", borderwidth=2)
button_frame.place(x=353.7, y=512)
button_frame.place(x=252, y=390)
offline_button = ttk.Button(
button_frame, text="Offline", style="W.TButton", command=offline_page
)
Expand All @@ -57,7 +57,7 @@ def local_page():
widget_destroy(root)
image_frame()
button_frame = ttk.Frame(root, relief="raised", borderwidth=2)
button_frame.place(x=353.7, y=512)
button_frame.place(x=252, y=390)
host_button = ttk.Button(
button_frame, text="Host", style="W.TButton", command=lambda: join_page(True)
)
Expand Down Expand Up @@ -92,7 +92,7 @@ def toggle():
previous_img = on_img

button_frame = ttk.Frame(root, relief="raised", borderwidth=2)
button_frame.place(x=317.5, y=512)
button_frame.place(x=225, y=390)
sound_label = ttk.Label(button_frame, style="W.TLabel", text="Sound")
sound_label.grid(column=0, row=0, sticky=tk.W)
sound_button = tk.Button(button_frame, image=previous_img, bd=0, command=toggle)
Expand Down
65 changes: 32 additions & 33 deletions chainRxa2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def call_this(
):
player_number, grid_size = int(player_number) + 1, int(grid_size)


def newgame_function():
widget_destroy(root)
call_this(
Expand Down Expand Up @@ -91,23 +90,28 @@ def call_join_start(
global cells, game_start
player_number, grid_size = int(player_number) + 1, int(grid_size)


def newgame_function():
widget_destroy(root)
call_join_start(
root,
local_page,
call_join,
widget_destroy,
home_page,
image_frame,
player_number - 1,
grid_size,
button_style,
isHost,
ipaddress,
sound_option,
)
# def newgame_function():
# global player_count

# if isHost:
# player_count = 1

# widget_destroy(root)
# call_join_start(
# root,
# local_page,
# call_join,
# widget_destroy,
# home_page,
# image_frame,
# player_number - 1,
# grid_size,
# button_style,
# isHost,
# isHostOnly,
# ipaddress,
# sound_option,
# )

def back_function():
call_join(
Expand All @@ -125,13 +129,13 @@ def call_again():
button_frame = ttk.Frame(root)
button_frame.pack(fill="both")

newgame_button = ttk.Button(
button_frame, text="New Game", style="W.TButton", command=newgame_function
)
# newgame_button = ttk.Button(
# button_frame, text="New Game", style="W.TButton", command=newgame_function
# )
back_button = ttk.Button(
button_frame, text="Back", style="W.TButton", command=back_function
)
newgame_button.grid(column=0, row=0, padx=5, sticky=tk.N)
# newgame_button.grid(column=0, row=0, padx=5, sticky=tk.N)
back_button.grid(column=1, row=0, padx=5, sticky=tk.N)

ttk.Separator(orient="horizontal").pack()
Expand All @@ -144,7 +148,6 @@ def call_again():

c.bind("<Configure>", cells.grid)
c.bind("<Button-1>", cells.numbering)


root.mainloop()

Expand All @@ -153,12 +156,14 @@ def waiting_page():
widget_destroy(root)
image_frame()
new_frame = ttk.Frame(root, relief="raised", borderwidth=2)
new_frame.place(x=210, y=512.5)

if not isHost:
new_frame.place(x=228, y=390)
text = f"Waiting other to join"

else:
text = f"Your IP Address is: {ipaddress}"
new_frame.place(x=185, y=390)

ip_label = ttk.Label(new_frame, style="W.TLabel", text=text)
ip_label.grid(column=0, row=0, padx=5, sticky=tk.N)
Expand All @@ -178,7 +183,6 @@ def server_start():
if isHost == True:
start_new_thread(server_start, ())


n = Network()
n.server = ipaddress
n.connect()
Expand All @@ -192,7 +196,6 @@ def server_start():
cells.myid = server_get[1]
cells.isOnline = True


def client():
global cells, game_start
tmpx = -1
Expand All @@ -205,7 +208,7 @@ def client():
while True:
clock.tick(60)
x, y, game_start, I = n.send([cells.x, cells.y, cells.playerIndex])

if first_time:
cord_list.insert(0, [x, y, I])

Expand All @@ -220,12 +223,10 @@ def client():
and cord_list[0][2] != cells.player
):


cells.x = x
cells.y = y
cells.execute()


first_time = False

start_new_thread(client, ())
Expand All @@ -234,9 +235,7 @@ def client():
if not isHost:
server_get = n.send([isHostOnly, isHost])
else:

server_get = n.send([isHostOnly, isHost, player_number - 1, grid_size])

waiting_page()

server_get = n.send([isHostOnly, isHost, player_number - 1, grid_size])

waiting_page()
12 changes: 6 additions & 6 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def start(ip, isHostOnly):
image_frame()

new_frame = ttk.Frame(root, relief="raised", borderwidth=2)
new_frame.place(x=210, y=512.5)
text = "IP Address: "
ipaddr = tk.StringVar()

Expand All @@ -60,21 +59,21 @@ def total_grid(event):

if not isHost:

new_frame.place(x=125, y=390)
ip_label = ttk.Label(new_frame, style="W.TLabel", text=text)
ip_label.grid(column=0, row=0, padx=5, sticky=tk.N)
ip_label.grid(column=0, row=0, padx=10, sticky=tk.W)

ip_entry = ttk.Entry(new_frame, textvariable=ipaddr, style="W.TEntry", width=30)
ip_entry.grid(column=1, row=0, sticky=tk.W)
ip_entry.grid(column=1, row=0, padx=10, sticky=tk.E)

def focus_in(*args):
ip_entry.delete(0, "end")

ip_entry.bind("<FocusIn>", focus_in)
ip_entry.insert(0, "Enter IP address")


else:

new_frame.place(x=100, y=390)
player_size = ttk.Combobox(new_frame)
player_size["values"] = values[:7]
player_size["state"] = "readonly"
Expand Down Expand Up @@ -119,6 +118,7 @@ def focus_in(*args):
back_button = ttk.Button(
new_frame, text="Back", style="W.TButton", command=local_page
)
back_button.grid(column=2, row=3, padx=5, pady=5)
column = 1 if not isHost else 2
back_button.grid(column=column, row=3, padx=5, pady=5)

root.mainloop()
4 changes: 2 additions & 2 deletions offline_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def gameStart():
widget_destroy(root)
image_frame()
player_seclection_frame = ttk.Frame(root, relief="raised", borderwidth=2)
player_seclection_frame.place(x=271, y=512.5)
player_seclection_frame.place(x=172, y=390)

no_of_players = ttk.Combobox(player_seclection_frame)
no_of_players["values"] = values[:7]
Expand Down Expand Up @@ -68,7 +68,7 @@ def gameStart():
widget.grid(padx=5, pady=3)

start_button_frame = ttk.Frame(root, relief="raised", borderwidth=2)
start_button_frame.place(x=300, y=606)
start_button_frame.place(x=205, y=460)
start_btn = ttk.Button(
start_button_frame, text="start", style="W.TButton", command=gameStart
)
Expand Down
9 changes: 4 additions & 5 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
cells = 0
grid_size = 8
direct_run = False
game_start = False
p = -1


def server_run(sound_option):
global player_count, p

game_start = False
global player_count, game_start, p

hostname = socket.gethostname()
ipaddress = socket.gethostbyname(hostname)
Expand Down Expand Up @@ -66,7 +65,7 @@ def threaded_client(conn):
cord_list = []
first_time = True
while run:
print("Player_count",player_count,"max_player",max_player)
print("Player_count", player_count, "max_player", max_player)
try:
Tx, Ty, TI = pickle.loads(conn.recv(2048))

Expand Down Expand Up @@ -99,7 +98,7 @@ def threaded_client(conn):
sys.exit()

print("Server is online")
while True:
while True:
conn, addr = s.accept()
print("connected to: ", addr)
player_count += 1
Expand Down

0 comments on commit 7d83cba

Please sign in to comment.