From f52f188b4f82f0eda64a77194664603439dc7a32 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Wed, 8 May 2019 14:52:56 -0400 Subject: [PATCH] Option to run on PySimpleGUI or PySimpleGUIWeb, Added Slider display --- DemoPrograms/Demo_Conways_Game_of_Life.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/DemoPrograms/Demo_Conways_Game_of_Life.py b/DemoPrograms/Demo_Conways_Game_of_Life.py index ce984754..b5c47464 100644 --- a/DemoPrograms/Demo_Conways_Game_of_Life.py +++ b/DemoPrograms/Demo_Conways_Game_of_Life.py @@ -23,7 +23,8 @@ # along with this program. If not, see . import numpy -import PySimpleGUI as sg +import PySimpleGUI as sg # Take your pick! Tkinter +# import PySimpleGUIWeb as sg # Or the Web! (Remi!) BOX_SIZE = 15 @@ -102,13 +103,15 @@ class GameOfLife: [sg.Text('Game of Life ', font='ANY 15'), sg.Text('', key='_OUTPUT_', size=(30,1), font='ANY 15')], [self.graph], [sg.Button('Go!', key='_DONE_'), - sg.Text(' Delay (ms)') , sg.Slider([0,400], orientation='h', key='_SLIDER_', size=(15,15)), - sg.Text(' Num Generations'), sg.Slider([0, 3000],default_value=400, orientation='h',size=(15,15), key='_SLIDER2_')] + sg.Text(' Delay (ms)') , sg.Slider([0,400], orientation='h', key='_SLIDER_', enable_events=True, size=(15,15)), sg.T('', size=(3,1), key='_S1_OUT_'), + sg.Text(' Num Generations'), sg.Slider([0, 3000],default_value=400, orientation='h',size=(15,15),enable_events=True, key='_SLIDER2_'), sg.T('', size=(3,1), key='_S2_OUT_')] ] self.window = sg.Window('Window Title', ).Layout(layout).Finalize() event, values = self.window.Read(timeout=0) self.delay = values['_SLIDER_'] + self.window.Element('_S1_OUT_').Update(values['_SLIDER_']) + self.window.Element('_S2_OUT_').Update(values['_SLIDER2_']) def draw_board(self): @@ -125,8 +128,11 @@ class GameOfLife: exit() self.delay = values['_SLIDER_'] self.T = int(values['_SLIDER2_']) + self.window.Element('_S1_OUT_').Update(values['_SLIDER_']) + self.window.Element('_S2_OUT_').Update(values['_SLIDER2_']) self.window.Element('_OUTPUT_').Update('Generation {}'.format(self.t)) + def manual_board_setup(self): ids = [] for i in range(self.N): @@ -137,6 +143,8 @@ class GameOfLife: event, values = self.window.Read() if event is None or event == '_DONE_': break + self.window.Element('_S1_OUT_').Update(values['_SLIDER_']) + self.window.Element('_S2_OUT_').Update(values['_SLIDER2_']) mouse = values['_GRAPH_'] if event == '_GRAPH_': @@ -159,3 +167,4 @@ class GameOfLife: if (__name__ == "__main__"): game = GameOfLife(N=35, T=200) game.play() + game.window.Close() \ No newline at end of file