change methode change_ship_size
This commit is contained in:
parent
8ff9815604
commit
5f87177e78
|
@ -83,8 +83,6 @@ def draw_field(window, field):
|
|||
btn.bind('<Button-1>', lambda e, x=r, y=c: left_button_click(field, x, y))
|
||||
btn.bind('<Button-3>', lambda e, x=r, y=c: right_button_click(field, x, y))
|
||||
btn.bind('<Enter>', lambda e, x=r, y=c: button_enter(field, x, y))
|
||||
for i in range(1, 5):
|
||||
window.bind(str(i), lambda size=i: change_ship_size(size))
|
||||
|
||||
buttons.append(btn)
|
||||
|
||||
|
@ -177,16 +175,16 @@ def button_enter(field, row, col):
|
|||
colorize(field, buttons)
|
||||
|
||||
|
||||
def change_ship_size(new_size):
|
||||
def keypress_handler(e):
|
||||
global ship_size
|
||||
if 1 <= new_size <= 4:
|
||||
ship_size = new_size
|
||||
|
||||
ship_size = int(e.keysym)
|
||||
return ship_size
|
||||
|
||||
|
||||
window = Tk()
|
||||
window.title("Ship Craft!")
|
||||
window.geometry('450x410')
|
||||
window.bind_all('<KeyPress>', keypress_handler)
|
||||
|
||||
set_ship(1, 1, 4, 1)
|
||||
set_ship(0, 6, 3, 0)
|
||||
|
|
Loading…
Reference in New Issue