Option to run on PySimpleGUI or PySimpleGUIWeb, Added Slider display
This commit is contained in:
parent
653d4084ff
commit
f52f188b4f
|
@ -23,7 +23,8 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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()
|
Loading…
Reference in New Issue